regex

Converting PHP Regex's to Javascript (or what are the differences?)

I have a form generator that uses (perl compatible) regexes for ther backend validation. Since the whole form is being dynamically generated it was fairly trivial to add a bit of jquery and then use the same regexes to validate on the client side pre submission. However, some of the time the regexes don't behave themselves in Javascrip...

In Perl, how can I get the matched substring from a regex?

My program read other programs source code and colect information about used SQL queries. I have problem with getting substring. ... $line = <FILE_IN>; until( ($line =~m/$values_string/i && $line !~m/$rem_string/i) || eof ) { if($line =~m/ \S{2}DT\S{3}/i) { # here I wish to get (only) substring that match to pattern \S{2}DT\S{...

how to remove non 'ui-*' words by invoking str.replace() with regexp

In Javascript, str = 'left ui-tabs ui-widget ui-widget-content center right'; Is it possible to remove non 'ui-*' words by invoking str.replace() with regexp ? The result after invoking str.replace() should be: str.replace(/ /, '') = 'ui-tabs ui-widget ui-widget-content'; I've tried some regexp patterns, but they doesn't work. ...

%:s/\([0-9]*\)_\(*\)/\2 will not rename files

can someone please edit %:s/\([0-9]*\)_\(*\)/\2 so that i can rename files. for example, if file name is 5555_word_word.jpg, then I want the file name to be word_word.jpg. i feel like I am so close! ...

Yaml Parser choking

Hey guys, I have a yaml snippet ... passwordregexp: '.{8},[0-9],[^0-9A-Za-z ],[A-Z],[a-z]' passwordregexpfailmessage: |- Contain at least 8 characters Contain at least 1 Number Contain at least 1 Special Character Contain at least 1 Upper Case Letter Contain at least 1 Lower Case Letter passwordresetperiod: 1000 pd...

Help with negative lookbehind in regular expressions

I am working on a ASP.NET response filter that rewrites URL's to point to a different domain in specific situations. Because ASP.NET chunks the response writes, my filter gets called several times before the page is fully streamed. This means that I need to be careful that each call to Regex.Replace doesn't double replace a url (You end...

Getting results from a regular expressions in c#

I have a regular expression which pulls name value pairs ([^=;]*)=([^;]*) "Data Source=server;Initial Database=myDB;foo=bar;" That works fine and I can get to the first result using m.Groups[0] // "Data Source=server" m.Groups[1] // "Data Source" m.Groups[2] // "Server" How do I get to the second and third set of matches? My term...

PHP - REG_BADBR error when using ereg() for regexp

Hello, I have this piece of code for email verification : function VerifRegisterEmail(&$email) { if(empty($email)) { return false; } $pattern_email = '^[[:alnum:]\.-_]+@[[:alnum:]\.-_]+\.[[:alpha:]]{2, 3}$'; if(!ereg('^[[:alnum:]\.-_]+@[[:alnum:]\.-_]+\.[[:alpha:]]{2, 3}$', $email)) { echo "emaill"; return false; ...

regular expressions to replace money pattern

I would like to ask for help with this, I wanted to check for a string matching a decimal followed by a letter (15M, 15.3M, 15T or 15.3T) and replace it with zeroes. Like these: 15M -> 15000000 15.3M -> 15300000 15T -> 15000 15.3T -> 15300 I tried doing this with str_replace but can't get it right. Hope someone can help me. ...

Regular expression to extract filename after a character and without extension

Hello, I am looking for help in how to create a regular expression that extracts a substring from a string that looks like the following: test123 #AMMA-TestFileName File's.xml to... AMMA-TEstFileName File's Basically, removing the first "#" and everything before it. In addition, removing the ".xml" file extension. Any help is appre...

Validate: Only letters, numbers and -

Hello, I would like to validate my users, so they can only use a-z and - in their username. validates_format_of :username, :with => /[a-z]/ However this rule also allows spaces ._@ Username should use only letters, numbers, spaces, and .-_@ please. Any ideas? Best regards. Asbjørn Morell ...

Regular Expressions: how to do "option split" replaces

Hello, those reqular expressions drive me crazy. I'm stuck with this one: test1:[[link]] test2:[[gold|silver]] test3:[[out1[[inside]]out2]] test4:this|not Task: Remove all [[ and ]] and if there is an option split choose the later one so output should be: test1:link test2:silver test3:out1insideout2 test4:this|not I came up with (...

Remove punctuation marks except apostrophe Regex

Hello. preg_replace ("/(\p{P})/", ' ', $str) removes apostrophes, and it should not. Please help ...

Javascript Match and RegExp Issue -- Strange Behavior

I have been trying to use a simple jQuery operation to dynamically match and store all anchor tags and their texts on the page. But I have found a weird behavior. When you are using match() or exec(), if you designate the needle as a separate RegExp object or a pattern variable, then your query matches only one instance among dozens in t...

What tools are there for debugging/stepping through a regular expression?

While there are many good online and offline tools for testing regular expressions, I have yet to find a tool (besides RegexBuddy) that lets me see the steps that the regular expression engine takes to find a match (or to find that there is no match, for that matter.) Does anyone know of any tools that do this? The reason I have initial...

PHP Regex problem with a complex target string

Hi, i need to parse dhcp leases table with php regex. but the thing is it contains different characters used in regex too. here is sample output lease 172.17.2.3 { starts 4 2009/07/16 11:54:39; ends 4 2009/07/16 12:54:39; cltt 4 2009/07/16 11:54:39; binding state active; next binding state free; hardware ethernet 00:50:56...

How do I use regex to split a string into characters?

I need to learn RegEx but don't have time to figure this out right now. -- So I'm attempting exploit the community's capabilities. I have a string containing a list of acceptable 1-character comment variables. String comments = "#;"; And I want: String[] parsedComments = {"#", ";"}; What RegEx string will solve my problems? Strin...

replace string in parentheses using regex

I have gone through all related topics here on regex and can't find one that really works for my case. What I want to do is: HLN (Formerly Headline News) => HLN which means: I would replace everything inside the parentheses to be "" (including the parentheses). My difficulty is how to find the pattern "(.+?)", when I tried it, it al...

Regex in python

I'm trying to use regular expression right now and I'm really confuse. I want to make some validation with this regular expression : ^[A-Za-z0-9_.][A-Za-z0-9_ ]* I want to make it so there is a limit of character (32) and I want to "match" all the string. ex: string : ".hello hello" -this should work string : ".hello hello /.." -T...

How to replace tokens in a string without StringTokenizer

Given a string like so: Hello {FIRST_NAME}, this is a personalized message for you. Where FIRST_NAME is an arbitrary token (a key in a map passed to the method), to write a routine which would turn that string into: Hello Jim, this is a personalized message for you. given a map with an entry FIRST_NAME -> Jim. It would seem that ...