ballouta Posted September 17, 2019 Share Posted September 17, 2019 Hello I spent literally 5 hours creating the following regex for a friend of mine! (?s)(?=Configuration)(.*?)(?>onal\)\:) The regex is supposed to capture several lines from a static content that starts with the word Configuration and ends with the word (optional): This content has sometimes a new blank line and sometimes two empty lines. Is it possible you kindly assist me in modifying the above regex so it extracts all the text needed, at the same time it ignores all new/blank lines? Text Sample: Hello Configuration There is something here s bbye optional): Hoping for this output: Hello Configuration There is something here s bbye optional): We are using the function reg_match. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/309245-my-regex-requires-modifications-to-ignore-blank-lines/ Share on other sites More sharing options...
requinix Posted September 18, 2019 Share Posted September 18, 2019 Regexes cannot modify the text that they capture. You'll need to find another method. Quote Link to comment https://forums.phpfreaks.com/topic/309245-my-regex-requires-modifications-to-ignore-blank-lines/#findComment-1569799 Share on other sites More sharing options...
ballouta Posted September 18, 2019 Author Share Posted September 18, 2019 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/309245-my-regex-requires-modifications-to-ignore-blank-lines/#findComment-1569822 Share on other sites More sharing options...
cyberRobot Posted September 23, 2019 Share Posted September 23, 2019 Did you figure out a solution? One potential option, without regex, is to process the input line by line. Once you locate the line that starts with "Configuration", you can start ignoring lines that are blank. You would ignore lines that are blank until you reach the line that ends with "optional):". Then you would output the information as it is processed. Quote Link to comment https://forums.phpfreaks.com/topic/309245-my-regex-requires-modifications-to-ignore-blank-lines/#findComment-1569931 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.