Posts

Showing posts with the label regex-group

generic regex to capture various optional groups

generic regex to capture various optional groups I am looking for a method to select, using regex, lines containing various groups, some of them optional, and capture the groups - the found ones, of course. After reading here on stackoverflow and many experiments I came up with this general enough approach: ^.*?(?:.*?(aaa).*?|.*?).*?(xxx).*?(yyy).*?(?:.*?([^ n]+).*?|.*?).*?$ So the general term for optional groups is: (?:.*?(blabla).*?|.*?) The above approach has backtracking problems in case of: Any ideea how to create a generic enough regex able to capture optional groups? By generic I mean, like in the example I found, easily scalable up for various group patterns. Thanks. Hi. Please include a tag for one specific engine or language (perl, pcre, c#, etc…). Regular expression questions get better answers if they… show the pattern that isn't working, provide some examples of input text that should match, and also ones that shouldn't match . Describe...

Regex Extract URL's and their labels from HTML file

Regex Extract URL's and their labels from HTML file I have a large html file exported from Google doc. When opened in a text editor it appears as a single line. There are many URL's there which I need to extract. They appear in this form: <a class="c13" href="https://www.google.com/url?q=https://example.com/page1/&amp;sa=D&amp;ust=1530382105580000">Text Label One</a>SOME HTML TEXT HERE<a class="c13" href="https://www.google.com/url?q=https://example.com/page2/&amp;sa=D&amp;ust=1530382105719000">Text Label Two</a> <a class="c13" href="https://www.google.com/url?q=https://example.com/page1/&amp;sa=D&amp;ust=1530382105580000">Text Label One</a>SOME HTML TEXT HERE<a class="c13" href="https://www.google.com/url?q=https://example.com/page2/&amp;sa=D&amp;ust=1530382105719000">Text Label Two</a> So far I found this solution (?...