regex

awk: access captured group from line pattern

If I have an awk command pattern { ... } and pattern uses a capturing group, how can I access the string so captured in the block? ...

How to match !x but not !!x in JS regex?

Given the following text: This is!!xa simple string!xpattern I would like to get a regexp that matches the !x that's between "string" and "pattern" but not !!xa that's between "is" and "a". This regexp is to be used inside a string split(). I have tried several combinations but I cannot get a regexp that meets my needs. Perhaps my ex...

How to code an efficient blacklist filter function in php?

So, I have three arrays like this: [items] => Array ( [0] => Array ( [id] => someid [title] => sometitle [author] => someauthor ... ) ... ) and also a string with comma separated ...

Properly match a Java string literal

Hi, I am looking for a Regular expression to match string literals in Java source code. Is it possible? private String Foo = "A potato"; private String Bar = "A \"car\""; My intent is to replace all strings within another string with something else. Using: String A = "I went to the store to buy a \"coke\""; String B = A.replaceAll(...

.Net Removing all the first 0 of a string

I got the following : 01.05.03 I need to convert that to 1.5.3 The problem is I cannot only trim the 0 because if I got : 01.05.10 I need to convert that to 1.5.10 So, what's the better way to solve that problem ? Regex ? If so, any regex example doing that ? ...

regex how to: if something is at beginning of the line the match is on then don't match

I actually want to skip matches on lines that begin with "..." in this case. I already have: [^0]\\swarnings?(?!\\.|\\w) so I need to keep that functionality and add the don't match warning on lines starting with "..." Thanks! edit: I'm using javascript. ...

Ruby regexp to parse command line.

How can I parse strings in ruby like many command line utilities do? I've got strings similar to "command [--opt1=...] [--enable-opt2] --opt3=... arg1" and methods similar to command(opt1,opt2,opt3,arg1...). I want to let arguments to come in random order, some of them can be optional. At the moment I wrilte regexp every time I need to ...

PHP RegEx string Replace

Hi, I've recently written a javascript RegExp to cleanse my data at the front end, I now need to do exactly the same for my PHP back end but not having worked in PHP for a while I'm having trouble. Below is the javascript RegExp, can someone please help me convert this to PHP? var illegalChars = /[\(\)\<\>\,\;\:\.\~\@\#\$\!\%\^\&\*\'\?...

groovy or java: how can replace '\' with '\\' 'C:\www\web-app\StudyReports\test.bat'

hi, this might be trivial (please forgive me for that) but my eventual goal is to have a string like def newline= 'C:\\www\web-app\StudyReports\\test.bat' but my old line only have one '\', i tried different ways of using the following def newline=oldline.replaceAll(/\\/,'//') but did not work at ... could someone help me out. ...

Regex in Python

SO, I am trying create a simple regex that matches the following string: <PRE>><A HREF="../cgi-bin/hgTracks?hgsid=160564920&db=hg18&position=chrX:33267175-33267784&hgPcrResult=pack">chrX:33267175-33267784</A> 610bp TGATGTTTGGCGAGGAACTC GCAGAGTTTGAAGAGCTCGG TGATGTTTGGCGAGGAACTCtactattgttacacttaggaaaataatcta atccaaaggctttgcatctgtacagaagag...

Regexp for selecting spaces between digits and decimal char

I want to remove spaces from strings where the space is preceeded by a digit or a "." and acceded by a digit or ".". I have strings like: "50 .10", "50 . 10", "50. 10" and I want them all to become "50.10" but with an unknown number of digits on either side. I'm trying with lookahead/lookbehind assertions like this: $row = str_replace("...

regex in python, can this be improved upon?

I have this piece of code that finds words that begin with @ or #, p = re.findall(r'@\w+|#\w+', str) Now what irks me about this is repeating \w+. I am sure there is a way to do something like p = re.findall(r'(@|#)\w+', str) That will produce the same result but it doesn't, it instead returns only # and @. How can that regex be ch...

Regex - Match text between 2 characters

I need a regex pattern(s) that will match on words before a colon and also values between 2 characters. Here's the example, I have a string: str='`width: 1070px; padding: 0px 10px 0px 10px; height: auto; margin:0px auto 0px auto;`' from a stylesheet, I need one array to store the property only (the text before a colon), (prptyArra...

Regex to split a string (in Java) so that spaces are preserved?

I need to split a string (in Java) into individual words ... but I need to preserve spaces. An example of the text I need to split is something like this: ABC . . . . DEF . . . . GHI I need to see "ABC", " . . . .", "DEF", ". . . .", and "GHI". Obviously splitting on the space character \s isn't going to work, as all the spaces g...

Regex not operator

I need to use a regex to pull a value out a url domain that will exclude everything but the host (ex: wordpress) and domain type (ex .com). The urls are dynamic and contain 2-3 values for each result (www.example.com or example.org). I am trying to use this expression, but I am only getting back the first letter of every item I am attemp...

How to get the second word from a String?

Take these examples Smith John Smith-Crane John Smith-Crane John-Henry Smith-Crane John Henry I would like to get the John The first word after the space, but it might not be until the end, it can be until a non alpha character. How would this be in Java 1.5? ...

How to check if a character is a non-word boundary

In Java regular expression, it has "\B" as a non-word boundary. http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html If I have a 'char', how can I check it is a non-word boundary? Thank you. ...

How do you make a regular expression that matches a word with one randomly inserted character?

Hey all, i want to use a regular expression to match a word with one specified character randomly placed within it. I also want to keep that 'base' word's characters in their original order. For example, with the 'base' word of test and the specified character of 'y', i want the regular expression to match all the following, and ONLY t...

Can regex match be based on two lines of text?

Let's say I have def abc xyz abc And I want to match xyz abc as a whole Is this possible using the most generic RegEx possible? That is not the perl RegEx or .Net Regex which have multi line flags. I guess it would be BNF to match this. ...

Regex.IsMatch vs string.Contains

Is there any difference in speed/memory usage for these two equivalent expressions: Regex.IsMatch(Message, "1000") Vs Message.Contains("1000") Any situations where one is better than other ? The context of this question is as follows: I was making some changes to legacy code which contained the Regex expression to find whether a s...