Questions tagged [regex-greedy]

The greedy regex property causes the regex engine to repeat a regex token as often as possible. Only if that causes the entire regex to fail, give up the last iteration, and proceed with the remainder of the regex. The greedy regex tokens are `+`, `*`, `?` and the repetition using curly braces.

Example of Greediness

Using a regex to match an HTML tag the regular expression does not need to exclude any invalid use of sharp brackets. An HTML tag will be anything between sharp brackets.

If the test string is the following:

This is a <EM>first</EM> test.

With the <.+> patterh a expected match would be <EM> and when continuing after </EM>. But he regex will match <EM>first</EM>.

The reason is that the plus is a greedy token.

969 questions
3
votes
1 answer

Regex to extract string between digit pattern and colon or newline

I have to extract string between digit pattern and either a colon or newline (first occurence) my string would look like: 05-30-1306-29-13 …
user869375
  • 2,299
  • 5
  • 27
  • 46
3
votes
2 answers

REGEX needed in Java for extracting all WARN messages with description may or may not be multiline message

I am trying to write a regular expression for Input text, where i have to extract all WARN code with the message ahead. In general the WARN may or may not be multiline as shown below. [C] L1250 WARN k2 bw34 Flex - Sockets:<16>,…
3
votes
2 answers

PowerShell Regex: Capturing strings between two strings that is on multiple lines

I may have something like this: FIRST|[some text here] (newline) [insert text here] (newline) SECOND|A (newline) FIRST|[some text here] (newline) [insert text here] (newline) SECOND|B (newline) FIRST|[some text here] (newline) [insert text here]…
3
votes
3 answers

Getting function Content and function name in C with regular expression in python

I am trying to get function content (body) if the function's name matches a defined pattern what I tried so far: (Step1) get with a recursion all function bodies in a define C file {(?:[^{}]+|(?R))*+} (Step2) find all matches of wanted…
HOrst
  • 33
  • 4
3
votes
4 answers

RegEx for an autocomplete feature

I am writing a search bar with an autocomplete feature that is hooked up to an endpoint. I am using regex to determine the "context" that I am in inside of the query I type in the search bar. The three contexts are "attribute," "value," and…
3
votes
1 answer

How to exactly match the previous group including case insensitivity?

I think this is something that simply does not exist. But I know that some of the functionality exists in other regex engines, I'm hoping they maybe something similar to this. pattern = r""" ([a-zA-Z]) # Match a single letter and capture it…
Işık Kaplan
  • 2,815
  • 2
  • 13
  • 28
3
votes
2 answers

How to extract comma separated substrings from a string?

Need to parse the algorithms separated by comma in group. SSH Enabled - version 2.0 Authentication methods:publickey,keyboard-interactive,password Encryption Algorithms:aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc MAC…
3
votes
5 answers

RegEx for capturing values in nested brackets

I was trying to use a regular expression to match the inner text between two characters, but I am getting the wrong text I tried putting [A-z]* instead of .* for matching only the inner text and it worked. But I need to match non-letter characters…
3
votes
3 answers

How to convert reference list to data frame?

I have a list of references, e.g., references <- c( "Dumitru, T.A., Smith, D., Chang, E.Z., and Graham, S.A., 2001, Uplift, exhumation, and deformation in the Japanese Mt Everest, Paleozoic and Mesozoic tectonic evolution of central Africa: from…
Jiulin Guo
  • 31
  • 2
3
votes
5 answers

RegEx for matching specific phone numbers

I'm trying to see if a string matches my country's phone number format, which is the area code (two digits that may or may not be preceded by a 0 and might also be between parenthesis) followed by 8 or 9 digits in which there may be an dash…
aplneto
  • 127
  • 2
  • 10
3
votes
2 answers

How to store and remove a regex pattern at once?

I want to know if is possible to do this without checking for the regex pattern twice. I am on python 3 pp = re.search(r'(.)(.+)\1(.+)', word) word = re.sub(r'(.)(.+)\1(.+)', '', word) salv = pp.groups() word + = salv[0] + salv[0] + inverse(salv[1])…
Azazel
  • 183
  • 1
  • 1
  • 10
3
votes
1 answer

RegEx performance: Alternation vs Trie

For the Google Prettify syntax highlighter for the Wolfram Language, I need to match all identifiers against a large list of about 7000 built-in function names to highlight them as keywords. In the past, I simply used a regex consisting of many…
halirutan
  • 4,281
  • 18
  • 44
3
votes
3 answers

Java regex : find the last occurrence of a string using Matcher.matches()

I have following input String: abc.def.ghi.jkl.mno Number of dot characters may vary in the input. I want to extract the word after the last . (i.e. mno in the above example). I am using the following regex and its working perfectly fine: String…
Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
3
votes
2 answers

Regex match last occurrence of a string from multiple lines

I'm trying to match the last occurrences of a string from a log file. [03/03/2019 09:16:36] Moving message 123456789 from NEW to PENDING [03/03/2019 09:16:36] Retrieving file(s) of type DATAWAREHOUSE for 123456 [03/03/2019 09:16:36] collecting…
tuxian
  • 159
  • 5
  • 12
3
votes
1 answer

Ignore specific string using regex

We got input string as below. String inputstr = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus venenatis ultricies pulvinar. Sed sed faucibus orci, at pharetra ex. Donec lacinia massa sed nunc aliquet ultricies. Duis suscipit,…
KARAN
  • 1,023
  • 1
  • 12
  • 24