regex

Regex to get src value from an img tag

I am using the following regex to get the src value of the first img tag in an HTML document. string match = "src=(?:\"|\')?(?<imgSrc>[^>]*[^/].(?:jpg|png))(?:\"|\')?" Now it captures total src attribute that I dont need. I just need the url inside the src attribute. How to do it? ...

How can I jump to next line after condition has been satisfied in Perl?

The following is the data I am working on: __DATA__ Node 1: 98 debug : fill 100 102 debug : fill 104 Node 2: 88 debug : fill 120 152 debug : fill 164 I want to write a regex/(or whatever is appropriate) to capture information from data below Node 1, say '98 : 100', but only after identification of N...

capture part of url with regex

Ok I promise I'll learn regular expressions tonight but right now I need a quick fix. (Really, I swear I will!) How do I extract the value of what comes after name= this url: page?id=1&name=hello In this case I would be trying to isolate 'hello'. Thanks! ...

How can regex ignore escaped-quotes when matching strings?

Hi, I'm trying to write a regex that will match everything BUT an apostrophe that has not been escaped. Consider the following: <?php $s = 'Hi everyone, we\'re ready now.'; ?> My goal is to write a regular expression that will essentially match the string portion of that. I'm thinking of something such as /.*'([^']).*/ in order t...

Regex - Match a Pattern Before a Character

Hi, I'm currently building a toy assembler in c# (going through The Elements Of Computing Systems book). I need to match a very simple pattern, I thought this would be a good time to learn some regex but I'm struggling! In the following examples I'd just like to match the letters before the '=' M=A D=M MD=A A=D AD=M AMD=A I've ...

A regex I have working in Ruby doesn't in PHP; what could the cause be?

I do not know ruby. I am trying to use the following regex that was generated by ruby (namely by http://www.a-k-r.org/abnf/ running on the grammar given rfc1738) in php. It is failing to match in php, but it is successfully matching in ruby. Does anyone see what differences between php's and ruby's handling of regexes that might expla...

Regex replacement with Emacs

I am trying to do a search and replace with regexs. Suppose I have a foreach(foo1.txt, foo2.txt, foo3.txt, foo4.txt). And I want to put " around each item in the list. I thought- from the documentation - that this regex would work (foo[1-4]\.txt) -> "\&". But it doesn't. What am I doing wrong? ...

How can I capture the contents of one or more strings using a regex?

Let's say I have the following three strings: (section1){stuff could be any character, i want to grab it all} (section1)(section2){stuff could be any character, i want to grab it all} (section1)(section2)(section3){stuff could be any character, i want to grab it all} So if applied regex to my expressions, for the first I would get: ...

Help with building Regex to extract text of HTML tag

Hi, I am trying to build a regular expression to extract the text inside the HTML tag as shown below. However I have limited skills in regular expressions, and I'm having trouble building the string. How can I extract the text from this tag: <a href="javascript:ProcessQuery('report_drilldown',145817)">text</a> That is just a sample o...

Java Regular Expression, match everything but

Hi all, I would like to match everything but *.xhtml. I have a servlet listening to *.xhtml and I want another servlet to catch everything else. If I map the Faces Servlet to everything (*), it bombs out when handling icons, stylesheets, and everything that is not a faces request. This is what I've been trying unsuccessfully. Patter...

Any way to get result of a simple calculation expression?

I have some values in a configuration file (XML file) with some values like this: <IncreamentInSeconds>24*60*60</IncreamentInSeconds> ... I could put 86400 value there, but it is more descriptive as a calculation expression. This is just a simple example. There are some other expressions as well, but they are all in a kind of calcul...

RegEx to get path of file, without domain

Hi there, I'm new to regular expressions, and have no clue where to start, it's like a diff language to me. But I need one quick to accomplish a task. I need to take http://www.domain.com/folder1/folder2/file_path.txt and get just /folder1/folder2/file_path.txt from it. Thanks! ...

How to find the pattern $iperf in the file using perl

How can I find and display the word $iperf in a file The file will look like this $iperf -c 172.29.38.67 -m -M 64 -i 5 -t 20 -P 10 WARNING: attempt to set TCP maximum segment size to 64, but got 536 WARNING: attempt to set TCP maximum segment size to 64, but got 536 WARNING: attempt to set TCP maximum segment size to 64, but got 536 ...

When to use Regex vs Built in String Methods?

I've noticed a lot of little debates about when to use regex and when to use a built in string function like String.Replace() (.NET). It seems a lot of people recommend always, always, always using regex whenever you deal with strings at all (besides just displaying them). Is this really best practice or just a wrong impression on my p...

Date parsing with regular expressions in JavaScript

I'm using match() in JavaScript to parse a dates from an RSS feed, I just can't get my head around the correct regular expression to find the date format. Here's the date: 2009-05-11 16:59:20 And the regular expression so far: if (dateToParse.match(/^\d\d\d\d-\d\d-\d\d/)) { dateTimeSeparator = " "; monthIndex = 0; ...

Transform a date using a regular expression from 24Dec to 24/12 or 24/12/2009

I get travel confirmations that look like this: "SQ 966 E 27JUL SINCGK" = "Airline Space Flight Space BookingClass Space Date_with_Month_as_name Space 3LetterFrom 2LetterTo". I can chop all this into pieces using a regex to submit it to a website. But the site would expect instead of 27JUL 27/07/2009 or at least 27/07. Is there a way t...

Equivalent to Python’s findall() method in Ruby?

I need to extract all MP3 titles from a fuzzy list in a list. With Python this works for me fine: import re for i in re.compile('mmc.+?mp3').findall(open("tracklist.txt").read()): print i How can I do that in Ruby? ...

How can I join multiple regex matches into one array element using Perl?

Following is the script for matching regex and storing value in array: sub b1 { # print $_; my @file = @_; my @value; my $find = qr/(\s+)([0-9]+)\s([A-Z])\s[0-1].[0-9]+\s->\s([A-Z])\s/; foreach my $file(@file){ push (@value, $file=~ /$find/) ; print "\n"; } ...

Get code outside quotes with regexp in javascript

Is there a way to get a piece of code that is not between quotes (single or double) in javascript with regular expressions? if i have this string: 'this is a test "this shouldn't be taken"' the result should be: 'this is a test' ...

How can I validate a property against a regular expresssion and still allow it to be null or empty?

I'm using the Validation Application Block from Microsoft. I have a string property which holds a phone number. I have a RegexValidator on it which works pretty well for ensuring only phone number type strings are in the property, but the property should also allow values that are null or an empty string. Currently the this validator ...