regex

Python: Identifying a numeric string?

I tried a couple of approaches, I am really only concerned with performance, not correctness. I noticed that the regex based implementation is about 3-4x slower than the one that uses type coercion. Is there another, more efficient way of doing this? def IsNumber(x): try: _ = float(x) except ValueError: return Fa...

In C# regular expression why does the initial match show up in the groups?

So if I write a regex it's matches I can get the match or I can access its groups. This seems counter intuitive since the groups are defined in the expression with braces "(" and ")". It seems like it is not only wrong but redundant. Any one know why? Regex quickCheck = new Regex(@"(\D+)\d+"); string source = "abc123"; m.Value /...

Regex: How do you get/extract information from an email using regular expressions (in ruby)?

Hello. I'm trying to extract information from an email address like so in ruby: Email: Joe Schmo <[email protected]> to get these three variables: name = ? email = ? domain = ? I've tried searching everywhere but can't seem to find how to do it correctly. Here's what I have so far: the_email_line = "Email: Joe Schmo <joeschmo@ab...

need help with Preg_replace Regular expressions

these word1 and word2 is in brackets want to remove the whole line depends on word2 [word1] something-line-text [word2] some text again want to replace some text with another depends on word2 [word1] something-line-text [word2] some text again into REPLCACEDTEXT something-line-text some text again some line text (something/...

JavaScript Regex Compile()

Is there a shorter way to write this? var needed = /\$\[\w+\]/mi; needed.compile(/\$\[\w+\]/mi); Why do I have to pass the pattern back into the regex when I've already declared it in the first line?! ...

Regex Help, How do I make order of expressions not matter?

I can't figure out how to get the order of the incoming string parameters (price,merchant,category) will not matter to the regex. My regex matches the parts of the string but not the string as a whole. I need to be able to add \A \Z to it. Pattern: (,?price:(;?(((\d+(\.\d+)?)|min)-((\d+(\.\d+)?)|max))|\d+)+){0,1}(,?merchant:\d+){0,...

JavaScript: Refactoring looping regex

How might this be improved, as it pertains to the loop and the regex replace? var properties = { ... }; var template = element.innerHTML; for (var name in properties) { template = template.replace (new RegExp('\\${' + name + '}', 'gm'), properties[name]); } element.innerHTML = template; Is there a way I could get all the...

Python MediaWiki table regex (find strings of a particular format, then extract substrings within)

I'm trying to find all strings of the format {{rdex|001|001|Bulbasaur|2|Grass|Poison}} in a large text file, and then extract the substrings corresponding to the first 001 and to Bulbasaur, perhaps as a tuple. I'm assuming regex with capturing groups can be used for both; could anybody tell me the appropriate regex to use in Python 3.1 ...

How to use javascript regex to check for "empty" form fields?

Hi All: I am working on a php+javascript based project and have already made up a mockup page at : my website I knew how to use javascript or php to check whether a particular field of form is "empty"or not, that is, whether it contains alphanumerical characters other than whitepsace characters(for instance, space, tab and newline). H...

How to use regular expressions to extract the term inbetween the square brackets in PHP?

I have something like: $string1="dog fox [cat]" I need the contents inside [ ] i.e cat another question: if you are familiar with regex in one language, will it do for the other languages as well? ...

Regex to remove EVEN lines

I need help to build a regex that can remove EVEN lines in a plain textfile. Given this input: line1 line2line3line4line5line6 It would output this: line1line3line5 Thanks ! ...

Differences among .NET Capture, Group, Match

Hi, guys! I am making a small applicaiton using .NET Regex types. And the "Capture, Group and Match" types totally confused me. I have never seen such an ugly solution. Could someone explain their usage for me? Many thanks. ...

How do I match accented characters in preg_match()?

I've read how accented characters might sometimes match [a-z]. What I'd like to know is how I could match a specific accented character. Obviously, preg_match('/[ñ]/', 'ñ') does not work. ...

java email extraction regular expression ?

I would like a regular expression that will extract email addresses from a String (using Java regular expressions). That really works. ...

Simple java regexp problem

Why this code would fail? assertTrue(Pattern.matches("[^a-zA-Z0-9]", "abc;")); ...

How to replace uppercase letters to lowercase letters using regex in Eclipse?

I'd like to go through all of my source code files and replace every occurence of k_Xyyy with k_xyyy (switch the first letter after k_ from uppercase to lowercase). I'm using the eclipse dialog to search and replace multiple files. Right now I have the regex \bk_([A-Z]). How do I specify the replacement string of the regex? ...

How can I match query string variables with mod_rewrite?

Suppose I have URLs with query string parameters like these: /index.php?book=DesignPatterns&page=151 /index.php?book=Refactoring&page=157 Using mod_rewrite, how can I redirect them to SES URLs like these? /DesignPatterns/151 /Refactoring/157 ...

regex match question

Hey Guys, I want to match any of these cases with a regex. I have the header text, but I need to match it with the (possible) corresponding HTML: <h1>header title</h1> <h2>site | header title</h2> <h3 class="header">header title</h3> <h2>header title 23 jan 2009</h2> <h1>header title</h1> I have this: /(<(h1|h2|h3))(.+?)".$title."(...

best way to transform a string to array.

I have an array $AR I have a string "set[0][p1]" When given this string, I need the best way to access the array at $AR['set'][0]['p1'] I have total control on that string, so I need not to worry from injections and stuff, and I can be sure it will be well formatted. There is no way I can put the p1 inside ' to be "set[0]['p1']" ...

help with regex -- require AM/PM substring at end

I'm using php's preg_match to get a named subgroups from a string. I'm parsing user-generated date/time strings into well-formatted date/time tokens. Here's my regex ~(?P<month>\d?\d)(/|-)(?P<day>\d?\d)(/|-)(?P<year>\d\d\d?\d?) +(?P<time>[\d: +((A|a)|(P|p))(M|m)]+)~i And it correctly parses dates like 01-17-10 09:30 pm 2/1/2010 06...