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
-2
votes
2 answers

How to capture multiple sequence of numbers as repeated groups?

I have a URL that contains multiple sequences of numbers I want to capture them all in groups suppose I have the following https://www.example.com//first/part/54323?key=value or https://www.example.com/first/12345/second/part/part2/5432?key=value I…
Mohab
  • 109
  • 2
  • 8
-2
votes
1 answer

Is there any point in using non-greedy in the middle of pattern in Regex Python

I am currently learning Python and was playing around with regex. I have noticed that I can't make sense of using regex non-greedy, if it isn't in or before the end of a pattern. x = "From someone.name@gmail.com Sat Jan 5 09:14:16 2008" y =…
Confucii
  • 3
  • 3
-2
votes
2 answers

Escaping in regex expression python

I'm looking to extract the id tag from the following field of data: {"purchased_at":"2020-04-21T05:55:30.000Z","product_desc":"Garnier 2019 Shampoo","onhold":{"copyright":true,"country_codes":["ABC"],"scope":"poss"},"id":"8745485"} The regex I'm…
Newbie
  • 29
  • 5
-2
votes
1 answer

matching regex in awk/gawk

Can someone make the awk line below work in awk please. The syntax uses the standard PCRE regex standard (and i need to expect that some non-numeric characters are preceded to the first number, that is the string can look like "++3.59 ± 0.04* ").…
atapaka
  • 1,172
  • 4
  • 14
  • 30
-2
votes
1 answer

How to get the invoice number and Customer PO using a regex from the below text?

Credit Notes - Original Invoice Number : 362/867/88540129 Customer PO : 124698753 Invoice Date : 2019-10-17 Reference A : BONNEVILLE POWER Sales Order : UTS003832 ADMINISTRATIO Business Partner : BP0042488 Customer Tax : 12-9871234
-2
votes
1 answer

Extract the fields in json log if the filed exists using regex

I am trying to extract the fields in the below sample…
-2
votes
1 answer

RegEx for capturing digits in a string (PHP)

I am pulling in job numbers and matching them to data in a mysql database, then retrieving the matching data. If my job number is 123456 then it matches up fine and I get results. Some are 123-456 some are 12-text, while some are…
-2
votes
2 answers

How to extract part of a string with slash constraints?

Hello I have some strings named like this: BURGERDAY / PPA / This is a burger fest I've tried using regex to get it but I can't seem to get it right. The output should just get the final string of This is a burger fest (without the first whitespace)
-2
votes
2 answers

RegEx for capturing digits from a string

I have this String: String filename = 20190516.BBARC.GLIND.statistics.xml; How can I get the first part of the String (numbers) without the use of substrings.
Apollocy
  • 67
  • 2
  • 8
-2
votes
1 answer

To match any number greater than 15 using regexp

I tried to match any number greater than 15 using the following regexp: 0*[1-9][6-9][0-9]* But I can match only 2 digit number eg. I can unmatch successfully 12 or 13 (less than 15) , whereas I am unable to match 105, 124 etc.. Anyone help me out…
prasanna kumar
  • 257
  • 3
  • 4
  • 17
-2
votes
2 answers

Why does a*a match aaa?

I am using python3 re module - I find that a*a matches aaa. I thought that regex was greedy by default (unless we override it to be lazy with ?) - so, a* would have matched the entire string, and the trailing a in the pattern would fail. However, it…
Anand
  • 3,690
  • 4
  • 33
  • 64
-2
votes
2 answers

Python Regex matcher until two characters like a OR condition

My question is quite simple I'm trying to come up with a RE to select any set of words or statement in between two characters. For example is the strings are something like this : ') as whatever ' and it can also look like ') as…
Chandra Kanth
  • 427
  • 5
  • 14
-2
votes
1 answer

Regex for get words After matching words

In below content, I need the regex for get the commits content value after match "commits": Please suggest regex pattern for achieve that. "{"commit":{"id":"f0180cb5d2f71906bc3875f3526a85c73cd4bf35","short_id":"f0180cb5","title":"Update…
Kali
  • 21
  • 3
-2
votes
1 answer

python Non greedy regular expression searching too many data

String: 'str1str2str2str4' I want to search and get only first "td" tag which contains text: "str2". so I tried two different non greedy expressions as below: >>> mystring =…
dagpag
  • 3
  • 2