regex

How to extract email address from a string using perl?

How to extract emails address from a string using perl and to put the email addres into a variable? My strings looks like Ben Tailor <[email protected]> [email protected], [email protected], Ben Tailor <[email protected]> I tryed this $string ="Ben Tailor <[email protected]>"; $string =~ /\b([^\s]+@[^\s]+)\b/g ; print $string;...

Regular Expression to Validate Long URLs in PHP

I am looking for help in creating a Regular Expression that validates a URL of very long length (eg. a very long Google Maps address). I am new to regular expressions and I am using it in PHP with preg_match(). I have used the expression: preg_match('/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/...

Speeding up regular expressions in Python

I need to quickly extract text from HTML files. I am using the following regular expressions instead of a full-fledged parser since I need to be fast rather than accurate (I have more than a terabyte of text). The profiler shows that most of the time in my script is spent in the re.sub procedure. What are good ways of speeding up my proc...

How to make this PHP URL parsing function nearly perfect?

This function is great, but its main flaw is that it doesn't handle domains ending with .co.uk or .com.au. How can it be modified to handle this? function parseUrl($url) { $r = "^(?:(?P<scheme>\w+)://)?"; $r .= "(?:(?P<login>\w+):(?P<pass>\w+)@)?"; $r .= "(?P<host>(?:(?P<subdomain>[-\w\.]+)\.)?" . "(?P<domain>[-\w]+\.(?P<ex...

Javascript regex alphabetic with few international characters

I need a javascript function for validating alphabetic input with a few extra characters from the Italian languages, namely: àèéìòóù I saw a regex before with something like: [\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF] What are those codes named and where can I find the right values? I would like to use these into following function: ...

Given an ID, find and replace the last sentence with a span wrapper

Given the following: <div id="bigchuck"> <p>blah blah blah.</p> <p>yada yada yada.</p> <p>Tada. Bing bong the witch is dead. Door bell.</p> </div> How can JavaScript/JQUERY find the last sentence "Door bell" and wrap it with a tag, to result in: <div id="bigchuck"> <p>blah blah blah.</p> <p>yada yada yada.</p> <p>Tada. Bing bo...

extract filename from path

i need to get filename from file path string. For example, from this string \abc\def\filename.txt i need to get filename.txt trying to do this with regexp: $filepath="abc\filename.txt"; $filename = preg_replace("/.+\\/","",$filepath); but it gives me an error. What regex i should use to solve this? ...

How to preg_match parent div?

Hi guyz, I need to get all contents of div class = "parent" using preg_match, <div class = "parent"> <div id = "child1"> </div> <div id = "child2"> </div> </div> Anyone? ...

Are there any advantages to using the VB.NET Like Operator vs a RegEx?

Other than perhaps enhanced readability for very simple patterns, why would someone choose to use the Like operator in VB.NET over regular expressions for string pattern matching? Are there any advantages? ...

How do I choose a regular expression match at an arbitrary index?

I have a string that looks like: ABC-DEF01-GHI54677-JKL!9988-MNOP Between each - can be virtually any character repeated any number of times. I'm using this regular expression: [^-]* How do I make it 'match' the match at the 2nd index (e.g. DEF01)? Or the 3rd (GHI54677) or 4th (JKL!9988)? The engine I'm using doesn't let me sp...

elisp regexp search in strings, not buffers

I have been searching everywhere in the emacs lisp documentation for how to regular expressions search into a string. All I find is how to do this in buffers. Is there something I'm missing? Should I just spit my string into a temporary buffer and search for it there? Is this just the coding style of elisp, something I'll get used to?...

Legacy URLs in CakePHP using routes or htaccess

I'm in the midst of moving a site from "plain old" php to the CakePHP framework and I need to be able to handle some legacy URLs, for example: foo.com/bar.php?id=21 is the pattern of the current URLs, but in the new site using cake, that URL needs to redirect to: foo.com/blah/21 So basically, I need to be able to grab that ID numbe...

Need help with a Regex for parsing human typed times

I'm really new to Regex and working hard, but this has gone beyond simple in my opinion. I understand how to create the Regex object in .Net but I'm not sure how to use it for my specific purpose once I have a pattern. Regex regex = new Regex("(at ){0,1}[0-9]{1,2}(:[0-9]{2}){0,1}(?:[ap]m?){0,1}"); I need to be able to take a sentence...

regex to replace the last digit with a hyphen and a digit

Hi Is there a way to replace the last digit with a hyphen and a digit. original needs to be replaced with file01 file01-01 file02 file02-02 With AmarGhosh I solved this with names as ( select '/file01/some/file01' name from dual union all select '/file02/another/file02' name from dual ) selec...

perl regexp replace string with a substring of the regular expression

Hello I have a question concerning perl. Assume I have the following line in my file: DoMatchLong ( "ThisIsMyVariable", lThisIsMyVariable); I want to replace "ThisIsMyVariable" by cp_const_ThisIsMyVariable So my aim is: DoMatchLong ( cp_const_ThisIsMyVariable, lThisIsMyVariable); $count = s/(?<=")\w+(?=")/const_cmd_cp_$&/gx; lea...

Regex does not properly break down file path with a version number

Hi, I was using a regex pattern to break down the context path for a servlet. /{1,2}([^/{1,2}]+) This works great for simple paths like /User/folder1/folder2/folder3/. In more real world scenario however there seems to be a problem if one of the folder names contains a dotted version number, such as: /User/username/Library/Tomcat/...

Extracting an array of integers using a regular expression in javascript

I'm having real difficulty with this but I'm no javascript expert. All I want to do is get myself an array of all matches in a string which match a given regExp. The regExp being this : [0-9]+ ie. Any integer. So If I pass the string "12 09:8:76:::54 12" I should get arr[0]="12" arr[1]="09" arr[2]="8" arr[3]="76" arr[4]="54" arr[5...

Cycling through urls in a string and appending a value to it PHP regex

I have the following string for example: Welcome to my <a href="http://example.com"&gt;site&lt;/a&gt;. Feel free to <a href="http://localhost.com"&gt;contact me</a>. What technique may I use to evaluate this string to add '/id/123' at the end of both of the urls resulting in: Welcome to my <a href="http://example.com/id/123"&gt;site...

Ignoring white space for a Regex match

I need to match 8 or more digits, the sequence of which can include spaces. for example, all of the below would be valid matches. 12345678 1 2345678 12 3 45678 1234 5678 12 34567 8 1 2 3 4 5 6 7 8 At the moment I have \d{8,} but this will only capture a solid block of 8 or more digits. [\d\s]{8,} will not work as I don't want white s...

RegExp taking out Unique numbers outta n list of numbers(arranged linewise) [Using BareTailPro Log Matcher - Real Time Analyzer]

Hi, How can I extract unique numbers from a long list of numbers (arranged linewise). I need a regular expression to do that. I am using a log program called baretailpro which enables searching through a log data and display per regex. Example Input: 123 321 123 432 343 343 432 811 932 432 ...list extends upto n number linewise Exa...