regex

equivalent for regexp /<rr>(.*?)</rr>/<test>$1</test>/gi

I want to write simple program in C equivalent to the regular expression: /<rr>(.*?)<\/rr>/<test>$1<\/test>/gi. Does anyone have examples? ...

Remove MSWord formatting using ColdFusion Regex

We have a lot of data that contains nasty MS Word formatting like this: <!--[if !mso]> <mce:style><! v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} --> <!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:Tr...

Regular expression: if, else if, else

Hi, I am trying to parse FSM statements of the Gezel language (http://rijndael.ece.vt.edu/gezel2/) using Python and regular expressions regex_cond = re.compile(r'.+((else\tif|else|if)).+') line2 = '@s0 else if (insreg==1) then (initx,PING,notend) -> sinitx;' match = regex_cond.match(line2); I have problems to distinguish if and els...

Did $ use to sometimes match a newline in Perl?

I seem to remember that there were certain conditions under which $ would match a newline (not "just before"), but I can't find anything in the docs that would confirm that. Did that use to be true in an earlier version of Perl or am I dreaming? ...

Match whitespace but not newlines (Perl)

I sometimes want to match whitespace but not newline. So far I've been resorting to [ \t] . Is there a less awkward way? ...

Writing a regex to capture text between outer parenthesis

So I'm trying to a parse a file that has text in this format: outerkey = (innerkey = innervalue) It gets more complex. This is also legal in the file: outerkey = (innerkey = (twodeepkey = twodeepvalue)(twodeepkey2 = twodeepvalue2)) So I want to basically capture only the outerkey's text. I cannot guarantee that all of the text wi...

Closing open XML tags with regex

Basically I want to do the same as here which is done in Python. I'd like to replace all self-closed elements to the long syntax. Example <iframe src="http://example.com/thing"/&gt; becomes <iframe src="http://example.com/thing"&gt;&lt;/iframe&gt; Full example: <html> <head> <meta http-equiv="Content-Type" content="tex...

How to check input is only a number, letter and space?

I need to write some Javascript to check an input to only allow number and letter and '-' and '_' and space bar. Here is my regular expression var pattern = /^([a-zA-Z])([a-zA-Z0-9_-]){1,80}$/; Above regex does not include space bar. How can I add space bar condition into my regex. ...

Check if a string matches a regex and strip a part of it out for use.

I want to add an automatic embedding feature when a YouTube URL is used (http://www.youtube.com/watch?v=VID, where VID is the video's ID). For this, I need to check if the given URL, stored in the variable url, matches "/http:\/\/www\.youtube\.com\/watch\?v=([a-z0-9]+).*/i", then I need to strip out the VID to use it (e.g. put the VID i...

PHP Regular Expression to get IP address from /etc/hosts

I'm writing a PHP script that autoconfigures a device over Telnet, and I need to grab some IP addresses from /etc/hosts I need it to grab the IP address only, and assign it to a variable based on the hosts name. Example: 192.168.1.50 machine 192.168.1.51 printer 192.168.1.52 sigpad The PHP script should be like this: $machineip = "1...

What does preg stand for in PHP's functions?

Does anyone know what the preg in preg_match, preg_grep, etc. stand for? I know they use PCRE, which are 'Perl Compatible Regular Expressions.' ...

using Regex with conditions

I have the problem that I can only use one Regex.IsMatch to validate a string and I have to conditions with regular expressions to be matched for the same string, I've looking and seems that I can use regex conditionals like (?(?=regex)then|else) to match both regular expressions on the string value, but I can't reach the same result My...

Regex: Match only if string A is found and string B is not

I'm trying to write a regular expression that will essentially return true if string A is found and string B is not found. To be more specific, I'm looking for any file on my server which has the text 'base64_decode' in it, but not 'copyright'. Thanks! ...

How to create a view spliting one column to 2 or more using a regular expression?

We have a non normalized table that contains foreign key infomration as free text inside a column. I would like to create a view that will transform and normalize that table. E.g. a column that contains the following text: "REFID:12345, REFID2:67890" I want to create a view that will have REFID1 and REFID2 as 2 separate integer colu...

How to go from a multiple line sed command in command line to single line in script

So I have sed running with the following argument fine if I copy and paste this into an open shell: cat test.txt | sed '/[,0-9]\{0,\}[0-9]\{1,\}[acd][0-9]\{1,\}[,0-9]\{0,\}/{N s/[,0-9]\{0,\}[0-9]\{1,\}[acd][0-9]\{1,\}[,0-9]\{0,\}\n\-\-\-//}' The problem is that when I try to move this into a korn shell script, the korn shell throws er...

Need regex for all HTML <input /> tags which lack a specific attribute

I need a regex to match all self-closing <input /> tags which lacks a type attribute. For example, I want to find these: <input size="1" /> <input name="test" /> But not this: <input type="radio" /> Please note, this should be adaptable for any single attribute. I am just using type here as an example. FYI, I am performing a sear...

Regex headache...

I want to validate a some C# source code for a scripting engine. I want to make sure that only System.Math class members may be referenced. I am trying to create a regular expression that will match a dot, followed by a capital letter, followed by any number of word characters, ending at a word boundry that is NOT preceded by System.Ma...

Match a specific sequence or everything else with regex

Been trying to come up with a regex in JS that could split user input like : "Hi{user,10,default} {foo,10,bar} Hello" into: ["Hi","{user,10,default} ","{foo,10,bar} ","Hello"] So far i achieved to split these strings with ({.+?,(?:.+?){2}})|([\w\d\s]+) but the second capturing group is too exclusive, as I want every character to be...

What is wrong with the below regular expression(c#3.0)

Consider the below Case 1: [Success] Input : X(P)~AK,X(MV)~AK Replace with: AP Output: X(P)~AP,X(MV)~AP Case 2: [Failure] Input: X(P)~$B,X(MV)~$B Replace with: C$ Output: X(P)~C$,X(MV)~C$ Actual Output: X(P)~C$B,X(MV)~C$B I am using the below REGEXP @"~(\w*[A-Z$%])" This works fine for case 1 but falied for the second. Ne...

Difference between two regex pattern in javascript

Hi folks, I my application I am using below regex for pattern matching. Original Pattern : /(\w+\.){2,}/ig Above pattern added in one array. Since this pattern has comma ( , ) after 2, creating problem in some environment. As we know below concept in regex : {n} - matches n times {n, m} - matches at least n times, but not mor...