regex

RegExp to validate a formula (math expression with matched parentheses)?

I have used regExp quit a bit of times but still far from being an expert. This time I want to validate a formula (or math expression) by regExp. The difficult part here is to validate proper starting and ending parentheses with in the formula. I believe, there would be some sample on the web but I could not find it. Can somebody post a ...

regexp to match AlphaNumeric with pattern

If alphanumeric all numbers can't be 9's. If lengh of the string 7 must be 1 alpha + 6 numeric. ...

Need a better regex for group matching

Hi, Presently I'm using two regx: ABC.*1EFG ABC.*2HIJ to retrieve Line 1 and Line 2 from a text file. Is there a better single regex, so that both the lines(L1 and L2) from below can be matched. Line 1: ABCanystring1EFGanystring Line 2: ABCanystring2HIJanystring Line 3: ABCanystring2LMNanystring . . . Line n Thanks you in ...

MongoDB Regex Search on Integer Value

Hi, I want to regex search an integer value in MongoDB. Is this possible? I'm building a CRUD type interface that allows * for wildcards on the various fields. I'm trying to keep the UI consistent for a few fields that are integers. Consider: > db.seDemo.insert({ "example" : 1234 }); > db.seDemo.find({ "example" : 1234 }); { "_id" : ...

Matching (and replacing) groups of text within a string

I have string in the following format: blah IIF((doc.PostTypeId == 1), (Parse(doc.Id) > 1000), (doc.ParentId > 1000)) blah and I want to convert it to: blah (doc.PostTypeId == 1 ? Parse(doc.Id) > 1000 : doc.ParentId > 1000) blah So far I'm using the following regex string for the match IIF\((?<one>[^,]*?),\ (?<two>[^,]*?),\ (?<three...

Regular expression for validating numeric values

I current have the following regular expression to accept any numeric value that is seven digits ^\d{7} How do I improve it so it will accept numeric values that are seven or ten digits? Pass: 0123456, 1234567, 0123456789, 123467890 Fail: 123456, 12345678, 123456789 ...

java regex matching ip address and port number as captured groups

Hi, could please anybody tell me what is wrong with this regexp ? ((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\:([0-9]{2,5}) for matching this: assfasfas>192.168.1.1:8080192.168.222.43:8286 I need 192.168.1.1 and 8080 to be captured groups Thank you ...

Regex to catch all files but those starting with "."

In a directory with mixed content such as: .afile .anotherfile bfile.file bnotherfile.file .afolder/ .anotherfolder/ bfolder/ bnotherfolder/ How would you catch everything but the files (not dirs) starting with .? I have tried with a negative lookahead ^(?!\.).+? but it doesn't seem to work right. Please note that I would like to avoi...

regex question for removal of javascript malware

Been hit with some nasty javascript malware on my site. I know that each offending code block starts with the following: <script language=javascript><!-- (function() and ends with </script> I'd like to remove the nasty bits via regex on windows, using some sort of freeware regex replacement tool. Any suggestions here? Thank Yo...

Regex & BBCode - Perfecting Nested Quote

Hey there, I'm working on some BBcode for my website. I've managed to get most of the codes working perfectly, however the [QUOTE] tag is giving me some grief. When I get something like this: [QUOTE=1] [QUOTE=2] This is a quote from someone else [/QUOTE] This is someone else quoting someone else [/QUOTE] It will return: > 1 said...

Escaping '“' with regular double quotes using Ruby regex

I have text that has these fancy double quotes: '“' and I would like to replace them with regular double quotes using Ruby gsub and regex. Here's an example and what I have so far: sentence = 'This is a quote, “Hey guys!”' I couldn't figure out how to escape double quotes so I tried using 34.chr: sentence.gsub("“",34.chr). This get...

Extract known pattern substring from NSString (without regex)

I'm really tempted to drop RegexKit (or my own libpcre wrapper) into my project in order to do this, but before I do that I want to know how Cocoa developers manage to do half of this basic stuff without really convoluted code or without linking with RegexKit or another regular expression library. I find it gobsmacking that Cocoa does n...

How do I seperate Punctuations in a sentence with a space between each phrase and punctuation in C++?

I want to write a program in c++ that get a sentence and insert a space between each word and punctuation in it! in sed script this is done with this expression: sed -e "s/,\([^0-9]\)/ , \1/g" -e "s/\.\([^0-9]\)/ . \1/g" -e 's/\.[ ]*$/ ./g' -e "s/\'/ \' /g" -e 's/?/ ?/g' -e 's/\`\`/ `` /g' -e "s/\' \'/''/g" -e 's/(/ ( /g' -e 's/)/ ) /g...

Regex split string but keep separators

I'd like to do a Regex.Split on some separators but I'd like to keep the separators. To give an example of what I'm trying: "abc[s1]def[s2][s3]ghi" --> "abc", "[s1]", "def", "[s2]", "[s3]", "ghi" The regular expression I've come up with is new Regex("\\[|\\]|\\]\\["). However, this gives me the following: "abc[s1]def[s2][s3]ghi" --> ...

Regular Expression help

hi everyone. I can't seem to make my regular expression work. I'd like to have some alpha text, no numbers, an underscore and then some more aplha text. for example: blah_blah I have an non-working example here ^[a-z][_][a-z]$ Thanks in advance people. EDIT: I apologize, I'd like to enforce the use of all lower case. ...

Regular expression for dd/mm

Hi Please help me with a regular expression to validate the following format dd/mm This is for validating a Birthday field and the year is not required. Thanks ...

regex breaks on \n

hi segmentText = <input from textarea>; testRgx = [/( \d+\.| [^\W\d_]\.|.)+?([!?.。](?= |$)|$)/g]; arrSegments = segmentText.match(testRgx); This expression fails if segmentText has \n or other white spaces in it.I want to add \n in to the list of chars that the above pattern use [!?.。] => [!?.。\n] so that the segment is separate...

PHP Regular express to remove <h1> tags (and their content)

Hay, i can't seem to find any regular expressions online to remove <h1></h1> tags (and their content). Anyone lend a hand on this and help. ...

Getting specific values with regex

I need to knowingly isolate each row of the vCard and get its value. For instance, I want to get "5555" from X-CUSTOMFIELD. So far, my thoughts are: "X-CUSTOMFIELD;\\d+" I have been looking at some tutorials and I am a little confused with what function to use? What would my regex above return? Would it give me the whole line or ju...

How can I remove HTML span tags with a Perl one liner?

I want to perform the following vim substitution as a one-liner in the terminal with Perl. I would prefer to allow for any occurences of whitespace or newlines, rather than explicitly catering for them as I am below. %s/blockDontForget">\n*\s*<p><span><a\(.*\)<\/span>/blockDontForget"><p><a\1/g I've tried this: perl -pi -e 's/bl...