I'm developing a small code editor and I would like to match Strings so I can highlight them a different color.
Example:
myvar = array('VOLVO', 'TOYOTA')
Using regex expression \'.*\' I get one match 'VOLVO', 'TOYOTA'
However, what I want are two matches: 'VOLVO' and 'TOYOTA'
Is this possible to achieve with a single regex expression?
Someone did suggest the following expression:
\'[^\']*\'
Which in fact solves my problem: I get two matches, one for 'VOLVO' and one for 'TOYOTA'.
Related
I have a list of the following numbers and want a Regular expression that matches when a number is not in the list.
0,1,2,3,4,9,11,12,13,14,15,16,18,19,250
I have written the following REGEX statement.
^(?!.*(0|1|2|3|4|9|11|12|13|14|15|16|18|19|250)).*$
The problem is that it correctly gives a match for 5,6,7,8 etc but not for 17 or 251 for example.
I have been testing this on the online REGEX simulators.
This should resolve your issue..
^(?!\D*(0|1|2|3|4|9|11|12|13|14|15|16|18|19|250)\b).*$
In your earlier regex you were basically saying eliminate all numbers that start with 0/1/2/3/4/9!
So your original regex would actually match 54/623/71/88 but not the others. Also the 11-19 and 250 in the list were rendered useless.
Although as others have I would also recommend you to not use regex for this, as I believe it is an overkill and a maintenance nightmare!
Also an extra note "Variable length look arounds are very inefficient too" vs regular checks.
I would do \b\d+\b to get each number in the string and check if they are in your list. It would be way faster.
You can use the discard technique by matching what you do not want and capturing what you really want.
You can use a regex like this:
\b(?:[0-49]|1[1-689]|250)\b|(\d+)
Here you can check a working demo where in blue you have the matches (what you don't want) and in green the content you want. Then you have to grab the content from the capturing group
Working demo
Not sure what regex engine you are using, but here I created a sample using java:
https://ideone.com/B7kLe0
I'm using Regular Expressions to find and replace parts of the text that look like this pattern:
[Y](X)
where X and Y are different phrases,
and the search process is based on X only
The following pattern does the job, but it replaces more text
when there are nested brackets
\[.*\]\(X\)
e.g.
[ZZZ [Y](X)
Text Sample:
The [epidermis](Epidermis (skin)) (the outermost layer of skin) and the outer dermis (the layer beneath the epidermis).Contact dermatitis results in large, burning, and itchy rashes. These can take anywhere from several days to weeks to heal. This differentiates it from contact urticaria –
How can I fix my Regular Expression to avoid this?
If I understood correctly you wanted to use a positive look ahead like:
In this sample:
[epidermis](Epidermis (skin))
you do something like:
\[[^\[\]]*?\](?=\(Epidermis \(skin\)\))
I have this string, and I need to get the datetime out of it by using regex. I have little to no experience with regex and am stuck.
As an example, take this string: Vic-nc_20150406_0100
I want to get the following result: 201504060100
How am I to accomplish this? So far I've come up with this expression: ([0-9]{8})_([0-9]{4}), although the result is two groups (20150404 and 0100).
Another expression I've come up with is ([0-9]{8}_[0-9]{4}), now the result is 20150406_0100.
I either need to combine the groups or filter out the [_] somehow. Can anybody help me out?
Thanks in advance!
If you want to replace, then just take the value of two groups.
Find (\d{8})_(\d{4})
Replace \1\2 or $1$2 based on your program language.
I am using VBA and I want to extract the following:
TEST-1, TEST-11, TEST-111 or TEST-1111 from a cell.
The regex that I've currently got is:
RE.Pattern = "(TEST-\d{3,4})"
This just extracts cells with either TEST-111 or TEST-1111. (It does not extract TEST-1 or TEST-11, which I also need) I have tried several different iterations or my regex with no luck.
Does anyone have any ideas of how to do this?
Looks like you need to use "(TEST-\d{1,4})" regexp.
This regex match all your exampless (see http://myregexp.com?regex=TEST-%5Cd%7B1,4%7D&text=TEST-1%20TEST-11%20TEST-111%20TEST-1111)
Kinda new to Rgeluar expressions and for the benefit of learning wanted to know how to do the following on one line:
page matching regular expression: .pdf/$
and page containing "somestring"
and page excluding "someotherstring"
I can obtain my desired output using the 3 rules above. My question is can I put all into one line using regular expression? So the first line would be something like:
page matching reg exp: .pdf/$ somestring+ (then regex for does not contain in GA) someotherstring
Is it possible to put all in a oner?
Lookahead will help you to match multiple independent things in one expression, and even allows to require non-matching. In your case:
/^(?=.*somestring)(?!.*someotherstring).*\.pdf$/