Questions tagged [regex-look-ahead]

32 questions
3
votes
1 answer

Using negative lookahead in RegExp to correctly match image URLs wrapped in [img] tags?

Negative lookahead to match itself in RegExp I want to use a RegExp to match an image url that will have two cases: The first case it is a normal image URL, ending with .png and may contain some query string, at which point the RegExp will match it…
linjunchao
  • 33
  • 3
3
votes
4 answers

Regex that matches two or three words, but does no catpure the third if it is a specific word

I need to match a specific pattern but I'm unable to do it with regular expressions. I'm looking for people's name. It follows always the same patterns. Some combinations are: Mr. Snow Mr. John Snow Mr. John Snow (Winterfall of the nord lands) My…
Xbel
  • 735
  • 1
  • 10
  • 30
3
votes
1 answer

RegEx to match either words separated by dash or just a single word

So, the requirement for this is to match last names of people, separated by a dash between each last name. The base RegEx I am using for this is this one: (?=\S*[-])([a-zA-ZÑñÁáÉéÍíÓóÚúÄäËëÏïÖöÜüÀàÈèÌìÒòÙù'-]+) Basically I am limiting it to latin…
Mihail Minkov
  • 2,463
  • 2
  • 24
  • 41
3
votes
1 answer

Negative lookbehind not working as expected.How to prevent second group from capturing the string?

I want to reject strings that start with BT(uppercase and lowercase included) Original regex: ^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z]…
Codemaster
  • 145
  • 2
  • 13
2
votes
1 answer

PHP preg_split() if it is NOT a number, + sign, bracket, new line or tab

I have the following operation which splits a string whenever it encounters an alphabet: $splitOriginal = preg_split("/[a-zA-Z]/", implode('', array_slice($array, $key)), 2); I want to extend it in such a way that it splits the string whenever the…
user627341
  • 79
  • 8
2
votes
1 answer

Stop at first lookahead match with two options

I'm trying to generate a RegEx that grabs all the content in between "<" and ">" and stops if it finds a "|". For example: This is the link This is the link This is the link
David
  • 63
  • 5
1
vote
3 answers

Matching specific characters individually except in specific expression

Let's say I have a string: cat_dog_ !mouse= gog+cat I want to match specific symbols _!=+, but not in that part of this regex . So result should be __!=+ I've tried lookAhead:…
Iga
  • 85
  • 5
1
vote
2 answers

regex use of D\*

what is the need of adding \D* in this question answer Use lookaheads in the pwRegex to match passwords that are greater than 5 characters long, and have two consecutive digits. let sampleWord = "bana12"; let pwRegex = /(?=\w{6})(?=\D*\d{2})/; // …
1
vote
1 answer

Regex positive lookahead multiple occurrence

I have below sample string abc,com;def,med;ghi,com;jkl,med I have to grep the string which is coming before keyword ",com" (all occurrences) Final result which is I am looking for is something like - abc,ghi I have tried below positive lookahead…
Abhishek
  • 41
  • 5
1
vote
1 answer

Match Regex Pattern which does not only consist of certain characters

I'm trying to match Strings up to a certain size which do not only consist of certain characters. So for the first part it's rather easy. To match this: Yes: "abcde / asbas" Yes: "abcde/ asbas" Yes: "abcde/ ///" Yes: " ///aasd" Yes: "/// …
fnax8902
  • 13
  • 5
1
vote
1 answer

Regular Expression Match string after n lines only if another string before n lines matches in any Text Editor supporting PCRE

I have a PHP Database configuration file(opened in Code Editor supporting PCRE) which contains various engine's credentials for generating connection strings. Now as I mentioned in the question title, I want to match certain string "DB_DATABASE",…
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
1
vote
1 answer

How to split look-ahead regex into 2 plain regexes?

I have a look-ahead regex [^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0-9%*]). In my test it extracts 4 substrings from @@||imasdk.googleapis.com/js/core/bridge*.html: |imasdk .googleapis .com /core I need to rewrite it with 2 good-old regexes as i can't use…
4ntoine
  • 19,816
  • 21
  • 96
  • 220
1
vote
3 answers

How to select a specific character in regex if it match certain conditions

I'm trying to find a dash - from a string if it match certain conditions and only the dash should be selected by regex. Cases it should be selected - If both sides has space. Example: test - dash If right hand side has space. Example: test- dash If…
Jamen
  • 169
  • 8
1
vote
1 answer

Regex Matching to extract a text ending with space

Please help, I need to extract a text from a long sentence The text is as follows : Current Balance: INR2,137,381.99 8/9/2020 Impaired normal I would like to extract the amount from the above text and I used the regex (?<=Current…
sreenath s
  • 13
  • 2
1
vote
1 answer

Regex - Ignore if group has prefix

I am trying to capture 8 digit phone numbers in free text. This should be ignored if a particular string appears before. My regex: (\b(\+?001|002)?[-]?\d{4}(-|\s)?\d{4}\b) To Capture: +001 12345678 12345678 Not…
blackfury
  • 675
  • 3
  • 11
  • 22
1
2 3