I am looking for a regular expression for the following string:
SQL Err 100 on \TEST1.$PROD01.TEST.XYZ562
I want to search for anything with TEST*.$PROD*.TEST.XYZ*.
Can anyone help with the regular expression?
Basic effort was required, you could just tried it yourself and, I believe, find an answer on your own! For future needs, try site regex101.com, it helps to work with regulars.
So, you need to find a string containing TEST, then something, then . then $PROD value, again anything, and .TEST.XYZ, and finally anything, where $PROD is, as I understand, a variable without special characters (as [](){}.^\).
So, you get that:
TEST[^.]*\.<$PROD value should go here>[^.]*\.TEST\.XYZ
That should be enough. You will need to supstitude variable $PROD on your own, but I don't know your language, so I can't help with that part. Maybe something like this:
"TEST[^.]*\." + $PROD + "[^.]*\.TEST\.XYZ"
Related
Regular Expressions are incredible. I'm in my regex infancy so help solving the following would be greatly appreciated.
I have to search through a string to match for a P character that's not surrounded by operators, power or negative signs. I then have to insert a multiplication sign. Case examples are:
33+16*55P would become 33+16*55*P
2P would become 2*P
P( 33*sin(45) ) would become P*(33*sin(45))
I have written some regex that I think handles this although I don't know how using regex I can insert a character:
The reg is I've written is:
[^\^\+\-\/\*]?P+[^\^\+\-\/\*]
The language where the RegEx will be used is ActionScript 3.
A live example of the regex can be seen at:
http://www.regexr.com/39pkv
I would be massively grateful if someone could show me how I insert a multiplication sign in middle of the match ie P2, becomes P*2, 22.5P becomes 22.5P
ActionScript 3 has search, match and replace functions that all utilise regular expressions. I'm unsure how I'd use string.replace( expression, replaceText ) in this context.
Many thanks in advance
Welcome to the wonder (and inevitable frustration that will lead to tearing your hair out) that is regular expressions. You should probably read over the documentation on using regular expressions in ActionScript, as well as this similar question.
You'll need to combine RegExp.test() with the String.replace() function. I don't know ActionScript, so I don't know if it will work as is, but based on the documentation linked above, the below should be a good start for testing and getting an idea of what the form of your solution might look like. I think #Vall3y is right. To get the replace right, you'd want to first check for anything leading up to a P, then for anything after a P. So two functions is probably easier to get right without getting too fancy with the Regex:
private function multiplyBeforeP(str:String):String {
var pattern:RegExp = new RegExp("([^\^\+\-\/\*]?)P", "i");
return str.replace(pattern, "$1*P");
}
private function multiplyAfterP(str:String):String {
var pattern:RegExp = new RegExp("P([^\^\+\-\/\*])", "i");
return str.replace(pattern, "P*$1");
}
Regex is used to find patterns in strings. It cannot be used to manipulate them. You will need to use action script for that.
Many programming languages have a string.replace method that accepts a regex pattern. Since you have two cases (inserting after and before the P), a simple solution would be to split your regex into two ([^\^\+\-\/\*]?P+ and P+[^\^\+\-\/\*] for example, this might need adjustment), and switch each pattern with the matching string ("*P" and "P*")
I would like to remove hundreds on onmouseover events from my code. the evt all pass different variables and I want to be able to use dreamwaever to find and replace all the strings with nothing.
Here is an example
onmouseover="parent.mv_mapTipOver(evt,'Wilson');"
onmouseover="parent.mv_mapTipOver(evt,'Harris');"
onmouseover="parent.mv_mapTipOver(evt,'Walker');"
I want to run a search that will identify all of these and replace/remove them.
I have tried seemingly infinite permutations of things like:
onmouseover="parent.mv_mapTipOver(evt,'[^']');"
or
onmouseover="parent.mv_mapTipOver(evt,'[^']);"
or
onmouseover="parent.mv_mapTipOver(evt,[^']);"
or
onmouseover="parent.mv_mapTipOver(evt,'[^']+');"
And many more. I cannot find the regular expression that will work.
Any/all help would be appreciated.
Thanks a ton!
"." and "(" have special meaning in regular expressions, so you need to escape them:
onmouseover="parent\.mv_mapTipOver\(evt,'[^']+'\);"
I'm not sure if this is correct dreamweaver regex syntax, but this stuff is standard enough.
Try this one:
onmouseover="parent\.mv_mapTipOver\(evt,'.+?'\);"
And see it in action here.
When using reg expressions you have to be very careful about how you handle white space. For example the following piece of code will not get caught by most of the reg expressions mentioned so far because of the space after the comma and equals sign, despite the fact that it is most likely valid syntax in the language you are using.
onmouseover= "parent.mv_mapTipOver(evt, 'Walker');"
In order to create regexp that ignore white space you must insert /s* everywhere in the regexp that white space might occur.
The following regexp should work even if there is additional white space in your code.
onmouseover\s*=\s*"parent\.mv_mapTipOver\(\s*evt\s*,\s*'[A-Za-z]+'\s*\);"
I'm trying to get a correct regular expression for this problem:
I get a result from a webservice as a string that looks like this
tag: 54e16e66 (Mifare card standard)
I need to extract the 54e16e66 part (which is in hexa) only, regardless of what is before and after that part, i've tried several patterns, but I am not confident enough with regex and I can't seem to find a pattern that works.
Edit
"tag :" is aways present.
the hexa part I want to extract has variable length
what is after is a user comment, so it could be anything
Could someone help ? thanks in advance !
Michael
Assuming your string there is a good template, and assuming a posix regular expression parser,
/^tag: ([0-9a-f]{8})/
should work. If the length is variable, you would just change the {8} to {m,n}, where m and n are the minimum and maximum possible number of characters you can expect, respectively.
Hey everyone, I'm trying to type a regular expression that follows the following format:
someone#somewhere.com or some.one#some.where.com
There are no special characters or numbers permitted for this criteria. I thought I had it down, but I'm a bit rusty with regular expressions and when I tested mine, it failed all across the boards. So far, my regular is expression is:
^[a-zA-Z]+/.?[a-zA-Z]*#[a-zA-Z]+/.?[a-zA-Z]*/.com$
If anyone could help me, it would greatly be appreciated, thanks.
your regex looks good. I think you need to change the / to \ in front of the . .
Additionally, if you don't want someone.#somewhere..com pass your regex, u should change your regex to
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$
(not completely sure about the brackets () though, but i think that should be working)
its a backslash to espace dots. Also put the the parenthesis around the . and what follows otherwise an email like abc.#cde..com would be valid.
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$
It looks mostly OK. Change your / to \ though...
For the second case, I would ensure that if you have a . in the middle, it must be followed by more letters:
^[a-zA-Z]+(\.[a-zA-Z]+)?#[a-zA-Z]+(\.[a-zA-Z]+)?\.com$
I'm trying to formulate a regular expression which will recognise the search term truncated by any number of characters from the right.
For example, if the search term is "pickle", the regex should recognise "pi", "pick" but not "pickaxe".
Initially I came up with the following:
p(i(c(k(l(e)?)?)?)?)?
That works perfectly, but seems a crude way of doing it. Is there a better way of doing this? I had a look around for something similar to what I want, but I'm not entirely sure what to search for.
Due to the way regex works, yes, that's basically the most concise form.