FAQ Database Discussion Community


Regex match MAC Addresses (different delimiters, formatting, etc.) [closed]

python,regex,network-programming,mac-address,regex-lookarounds
I was trying to find a Python compatible Regex expression that would be best for matching MAC addresses, but exclude things that might be mistaken for them (e.g., SSH keys). Also, I'd like to match the different delimiters (e.g., -, :, or .), different formatting (e.g., *nix, Windows, Cisco), and...

How to match (group2.*|^.*)group1 when no instance of groups 1,2,3, or 4 are in between?

regex,regex-negation,regex-lookarounds
I'm using Python 3.4. Suppose we have four groups composed of regular expressions g1 = 'g11|g22|...|g1m' g2 = 'g21|g22|...|g2n' g3 = 'g32|g32|...|g3p' g4 = 'g41|g42|...|g4q' For example, g1 might be 'chickens|horses|bonnet(?>!blue )'. The groups are disjoint: no element in any of the four groups belongs to more than one group....

Failing to negate case 'qwe' with negative lookahead

regex,regex-lookarounds
What's wrong? I'm trying to exclude text("123", qwe); case, but it matches text\([^,]+,\s*(?!qwe)[^\)]*\); How I can make it accepts only function with second parameter not "qwe"?...

Detect Two Consecutive Single Quotes Inside Single Quotes

c#,.net,regex,regex-lookarounds
I'm struggling to get this regex pattern exactly right, and am open to other options outside of regex if someone has a better alternative. The situation: I'm basically looking to parse a T-SQL "in" clause against a text column in C#. So, I need to take a string value like...

Regex: how to select of the location with PHP [duplicate]

php,regex,regex-negation,regex-lookarounds
This question already has an answer here: RegEx match open tags except XHTML self-contained tags 36 answers Html code: <div username="bob"> <table> <tr> <td>name</td> <td>alex</td> </tr> <tr> <td>location</td> <td>London</td> </tr> <tr> <td>id</td> <td>123</td> </tr> </table> </div> <div username="apple"> <table> <tr> <td>name</td> <td>david</td> </tr>...

Negative look-ahead assertion in list.files in R

regex,r,regex-lookarounds
I try to list all files in a directory that do not start with "Camera1", but end with ".png". For doing so, I am using a regular expression in list.files in R. To exclude "Camera1", I tried to use a negative lookahead, but it doesn't work. Where is my mistake?...

Regex: match “group3.*group1” if group2 is not between groups 3 and 1

regex,python-3.x,regex-negation,regex-lookarounds
I'm using Python 3.4. I have three groups: g1 = 'g11|g12' g2 = 'g21|g22' g3 = 'g31|g32' I want to match any instance of g3, followed by anything except g2, followed by g1. Here are some strings on which I want to find a match: 'g31 anything or nothing g11'...

Regex Negate non-contiguous Pattern

regex,regex-lookarounds,negation
I want to match the word fleece where it is NOT followed (either immediately, or further on) by the word snow Input data: Mary had a little lamb, its fleece was white as snow balls The following regex's don't work as they all match, and shouldn't. I'm sure I have...

Search for (LaTeX) regex found NOT within another regex (math mode)

regex,regex-negation,regex-lookarounds
I'm trying to find all improperly-written commands in LaTeX that are NOT within math mode. That is, in the following, I want to match "\bad" but NOT "\good\" or "\math". Example of \bad command. Example of \good\ command. And $x=\math + y$ is also a good command. I figured out...

Regular expression to get last occurence until next char

regex,regex-lookarounds
I am trying to work out this regular expression and stuck - can anyone help. I have a string: "This is a string with a [flag NO MATCH] that should match [flag THIS] but dont want this [NO NO]" I want to capture the last occurance of flag enclosed in...

Regular expression to include numeric only or character only or ignore first two conditions if alpha numeric

javascript,regex,regex-negation,regex-lookarounds
I wrote Regular expression for the below cases : only numbers(length:4) only alphabets(should contain vowel) ([0-9]{1,4})|((?=[a-z]*[aeiou])[a-z]*) eg: 9987, tyde How to add the below condition? Ignore the first two cases if the string contains alphanumeric characters. eg: 9ty87 ...

Find pattern from regex

php,regex,regex-lookarounds
I have a regex pattern ^(?:(?:31(\\\/|-|\\.)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\\/|-|\\.)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\\/|-|\\.)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\\/|-|\\.)(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$ Can anyone tell me how to find possible matches from this regex pattern?...

advanced conditional regex with multi capturing and lookarounds

regex,regex-lookarounds
At work I need a regex to match different kinds of products in a huge old catalogue that was imported on digital support in a really bad way (lots of errors, different styles, etc). While matching, I have to capture the product's type and its diameter (the value inside the...

preg_replace() replace only one pattern but match another pattern

php,regex,preg-replace,regex-lookarounds
I am trying to replace a string with preg_replace() I want to replace only one pattern 'bbb' but I want to match that pattern and two more ('aaa' and 'ccc') exactly like for example input : 'zzz aaa bbb ccc xxx' pattern to match : 'aaa bbb ccc' output :...

Extract and count common word-pairs from character vector

r,regex-lookarounds,tm,qdap
How can someone find frequent pairs of adjacent words in a character vector? Using the crude data set, for example, some common pairs are "crude oil", "oil market", and "million barrels". The code for the small example below tries to identify frequent terms and then, using a positive lookahead assertion,...

Regex to exclude a specific string but not strings having the substring

regex,regex-negation,regex-lookarounds
I am currently in need of a regex that can exclude a specific string but not words that include that string. For example if you have a string made of 0's and 1's. Any string that contains any number of 1's and any number of 0's except 3 0's exclusively....

How can I create a regex to match the inner-most match or work from right-to-left?

regex,regex-negation,regex-lookarounds,regex-greedy,grunt-usemin
I'm trying to match the strings for image references but am picking up a little too much when there's an expression involved. In this example http://www.regexr.com/3b3ub, you'll see I'm doing good on the 1st and 3rd matches but I'm getting too much in the 2nd match. I only want the...

Remove non-alphabetic words from a sentence using regex

regex,regex-negation,regex-lookarounds
Is it possible to remove words in a sentence that doesn't contain a-z letters? I've thought about negative look arounds but wasn't successful. For example, This is a 1-2-a3 sample 12 -- 7-8 sentence becomes This is a 1-2-a3 sample sentence Assume all other punctuations were removed except dashes. Thanks!...

Regex first portion starts with number

javascript,jquery,regex,regex-lookarounds
Why does my JavaScript regular expression not work? var regexp = /^[1-9a-zA-Z][0-9a-zA-Z ]*$/; console.log(regexp.test('sfdf sfdf')); The rule is simple: the string must start with any number (0-9) followed by any number(s) and/or letter(s) and must allow whitespace. Some valid examples: 202Ab second text and maybe more 333333 second text and...

Regex pattern to have only one dot and match integer and decimal numbers

javascript,regex,regex-lookarounds
I'm struggling with creating proper regex pattern to match such strings: "3" // true "3." // true "3.1" // true "3.22" // true And such strings should fail matching: "3.." // false "3.222" // false My current regex /^\d+(\.\d{1,2})*$/ matches only decimal numbers. I've tried several updates to it but...

Regex to avoid data duplication in delimited string?

regex,regex-lookarounds,regex-greedy
I am trying to validate the data which will be string value with the , delimited. What I want is to validate that there should not be repetition of the same value within the sting. Ex. my value would be. data1 = "value1,value2,value3,va-lu4,value 6,value1";//should fail data2 = "value1,value2,value3,va-lu4,value 6";//should pass...

Struggling with negative lookahead in a regex

regex,regex-negation,regex-lookarounds
I humbly request for some guidance on using multiple negative lookaheads in a regex. I currently have a string that matches up against 2 regular expressions. String: Armadale Joe Bloggs 22-333-222 20001 Whitfords to Butler ^Armadale\D+\d{2}-\d{3}-\d{2}\D+2\d{4}\D+$ (Armadale|Fremantle|Butler|Mandurah|Midland|Thornlie)\D+(?![0-9]{2}-[0-9]{3}-[0-9]{2})2[0-9]{4}\D+$ How can I modify Regex 2 so that it doesn't match the string?...

Regular Expression Help - Lookahead

regex,regex-lookarounds
I'm trying to validate some input text (this is part of a larger regex) and basically I have a list of values, Replaced with arbitrary characters in this example and I want to match that they have the correct convention.. IE I want to match AAA001 but not AAA00 and...

Find Multiple Flagged String within String Python

python,regex,string,regex-lookarounds
I have multiple flagged strings: FLGSTdata1FLGEN FLGSTdata2FLGEN ... where FLGST is start flag and FLGEN is end flag. I combine those strings and add some garbage data, so it looks like this: garbagegarbageFLGSTdata1FLGENFLGSTdata2FLGENgarbagegarbageFLGSTdata3FLGEN... I need to get each of flagged strings from the combined strings. Here is what I've done...

lookbehind for start of string or a character

regex,python-2.7,regex-lookarounds
The command re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE) throws a sre_constants.error: look-behind requires fixed-width pattern error in my program but regex101 shows it to be fine. What I'm trying to do here is to match landmarks from addresses (each address is in a separate string) like: "Opp foobar, foocity" --> Must match...

Word not preceded by a regular expression

java,regex,regex-lookarounds
There are plenty of these questions but they all focus on having a couple of characters. In a text file i have TXX and txx and i need to find those. But I also have Base64 encoded pictures. Meaning I have "picture":"/9j/4AAQSkTXX . . . Basically TXX, txx can appear...

Regular expressions, negative lookahead anywhere in the string

regex,regex-lookarounds,negative-lookahead
Im sorry if this is asked and has an answer but I can't find it. I know about regex lookarounds and negative lookahead. Thing is that negative lookahead examines what comes right after current position in a string. What I need is to find and discard matches if string contains...