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
1 answer

Regex For accept alphapet and special charcter

For the below line ERROR: /var/lib/jenkins/workspace/example/test@script/Jenkinsfile not found Conditions: 1.Have to start the line with ERROR 2.where example/test will change dynamically How to achieve this through Regex
-2
votes
2 answers

Perl regex back reference not being greedy

This is a working regex: /(ANSI|AAMVA) (\d{6})(\d{2})(\d{2})(\d{0,2})((?:DL)|(?:ID))+(.*?)\g{-2}+([^"]+)/ This is a sample string: "@\n\nANSI 6334290212DL00389199ZO04420478DLDAQ3572928\nDAASMITH, JOHN DOE\nDAG\nDAL4389 NE 47TH…
Judd
  • 9
  • 1
-2
votes
3 answers

How to extract a interrogation sentence from a string

I have a string. For example : "This is a string.Is this a question?What is the Question? I Dont know what the question is. Can you please list out the question?" I want to extract the questions from this text using regex what i tried…
-2
votes
1 answer

How to stop this regex from being greedy?

I have the following regex http://regexr.com/3d1qb and it is one those that is greedy now I understand why this is happening. But how can I fix this? Currently it is matching the whole thing as one. But the way I want it is to be matched twice not…
Steve
  • 1,213
  • 5
  • 16
  • 29
-2
votes
1 answer

Match the shortest "lol" possible: `'looool lool lol loool'.match(/(lo+?l)/)[1] // => 'looool'`?

The above example returns the "leftmost longest" match. Likewise, this example returns the rightmost match: 'looool lool lol loool'.match(/.*(lo+?l)/)[1] // => 'loool' But i'm curious of a solution to match the shortest "lol" possible.
Nieralyte
  • 444
  • 1
  • 5
  • 11
-2
votes
1 answer

Regex - How to match at least n items in a list

I'm trying to write an expression in Regex where I want to match at least n of the items in my list. I'm trying to make a filter where I filter out users who have triggered at least three out of seven actions. Let's say I have a list of actions:…
AndréG
  • 1
  • 2
-2
votes
1 answer

Python Regexp do not capture www. or .com inside xyz word in text data

View this Demo RegExp I do not want to capture "xyz" word inside between www. or .com View Screen
Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76
-2
votes
1 answer

Regex Issues conflicts

Im not receiving any answers from stackover. is anything went wrong with me..? Please anyone help me in finding below Regex Problem. If there is Input text starting with "(ix) (a) This is Sample Sentence." , it matches for both Regex Patterns…
Praveen Hiremath
  • 4,209
  • 2
  • 17
  • 11
-3
votes
3 answers

How to remove repeated sequence of characters in a string?

Imagine if: $string = "abcdabcdabcdabcdabcdabcdabcdabcd"; How do I remove the repeated sequence of characters (all characters, not just alphabets) in the string so that the new string would only have "abcd"? Perhaps running a function that returns…
-3
votes
2 answers

How to Compare Two String With Optional Characters?

consider we have a function (in Django || python) which compares two strings, one is the correct answer and another is student answered string. correct = '(an) apple (device)' student_answerd = 'apple device' I want to check student_answered with…
Arash
  • 281
  • 3
  • 12
-3
votes
1 answer

RegEx for transforming the next text using PhpStorm's search and replace dialog

I need to transform text using regex TPI +2573
NM$ +719
Молоко +801
Прод. жизнь +6.5
Оплод-сть +3.6
Л. отела 6.3/3.9
Вымя +1.48
Ноги +1.61
to this one TPI +2573
NM$
-3
votes
1 answer

RegEx for replacing everthing and new lines in between two words

I am looking for a javascript regex for deleting all lines between two words including the words. I could find something like this Dim input = "one two three four START four five four five six END seven" Dim output = Regex.Replace(input,…
codeProtect
  • 39
  • 2
  • 5
-3
votes
2 answers

RegEx for matching commas inside array values

I am trying to parse a CSV file line by line String rowStr = br.readLine(); When i tried printing the rowStr i see the below "D","123123","JAMMY,"," ","PILOT" How can i remove the comma from a value field? I want to retain the commas outside.
ACP
  • 34,682
  • 100
  • 231
  • 371
-3
votes
2 answers

RegEx for matching square bracketed words with no parenthesis following

I'd like to extend the syntax of Markdown with a simple pre-processing option. When the text contains some words in squared brackets, but no parenthesis follows it: Example text with [some reference] to show. I'd like to extend it so that it becomes…
Zoltán Schmidt
  • 1,286
  • 2
  • 28
  • 48
-3
votes
1 answer

RegEx for special characters and decimals except for commas

Regex testing for special characters, decimal except for hyphen, commas, alpha-numeric. Attempt ^(\+|-)?([0-9]+)$/ I'm trying to write a regex to match special characters, decimal except for commas, a hyphen, alpha-numeric.