regex

Grab it if it's there, forget it if it's not Regular Expression

I'm parsing a file with address details. Sometimes the address has one fax number, sometimes it has two fax numbers (on separate lines). How can I say "If there's a second fax number, grab it. If not, forget it" to my regex engine? Here's an example with one fax number: Tel: +1 212 12345 Fax: +1 212 23456 District HQ: Sprin...

I need a regular expression to convert US tel number to link

Basically, the input field is just a string. People input their phone number in various formats. I need a regular expression to find and convert those numbers into links. Input examples: (201) 555-1212 (201)555-1212 201-555-1212 555-1212 Here's what I want: <a href="tel:(201)555-1212">(201) 555-1212</a> - Notice the space is gone <...

Javascript regex problem

I need to make html pages where I want to share Ad space with other adsense users. I am trying to use javascript to find and replace adsense code using regex expression but I am stuck. This is the piece of string I am trying to match. pub-111111111111111"; /* 336x280, created 12/12/12 */ google_ad_slot = "2222222222"; An...

How to parse out Timestamp from this String?

I have this sample string: Sample string 1: A^1.1#B^1#I^2#f^0#p^1#d^2010-07-21T08:52:05.222ZKHBDGSLKHFBDSLKFGNIF#%$%^$#^$XLGCREWIGMEWCERG Sample string 2: A^1.1#B^1#f^0#p^1#d^2010-07-22T07:02:05.370ZREGHCOIMIYR$#^$#^$#^EWMGCOINNNNNNVVVRFGGYVJ667VTG So, from these strings, I need to take out the time stamp: 2010-07-21T08:52:05.222 or...

substring match faster with regular expression?

Hello, After having read up on RE/NFA and DFA, it seems that finding a substring within a string might actually be asymptotically faster using an RE rather than a brute force O(mn) find. My reasoning is that a DFA would actually maintain state and avoid processing each character in the "haystack" more than once. Hence, searches in long...

Regex to remove all special characters from string?

I'm completely incapable of regular expressions, and so I need some help with a problem that I think would best be solved by using regular expressions. I have list of strings in C#: List<string> lstNames = new List<string>(); lstNames.add("TRA-94:23"); lstNames.add("TRA-42:101"); lstNames.add("TRA-109:AD"); foreach (string n in lstNam...

Replace text in PHP

We have a variable with hmtl code inside. <?php echo $list; ?> This will give something like: <li><a href='http://site.com/2010/' title='2010'>2010</a></li> <li><a href='http://site.com/2009/' title='2009'>2009</a></li> <li><a href='http://site.com/2008/' title='2008'>2008</a></li> Want to add class for each <li>, it can be taken f...

Parse URL with Regex using PHP

I have a url formatted like this: http://www.example.com/detail/state-1/county-2/street-3 What I'd like to do is parse out the values for state (1), county (2), and street (3). I could do this using a combination of substr(), strpos(), and a loop. But I think using a regex would be faster however I'm not sure what my regex would be. ...

Jquery, getting .css "background-color" in #000000 format?

I'm using a jquery plugin that seems to need the color in "000000" format but when I do this: currentcolor = $("#" + dividediting).css("background-color"); I get the output as: rgb(0,0,0) I'm wondering if there is a way to change the way it outputs or if I have to use regex to parse the result to get it to the needed format.. thank...

Can't get asp.net regular expression validator to work for blank passwords?

I do not want to allow blank passwords, but if I leave the textbox blank, the text property from the regular expression does not show up until I enter at least 1 character. How do I allow it not to have a blank password? I tried using the + sign instead of the * sign, but it still did not work. <asp:RegularExpressionValidator ...

How to split to the right of a number?

I'm trying to use Ruby to split to the right of a number. For example: H2SO4 How do you do this? I'd like to output ["H2", "SO4"] x.split(/\d+/) yields: ["H", "SO"] x.split(//) yields: ["H", "2", "S", "O", "4"] Both cool but not exactly what I'm looking for. ...

Regex expression to replace over 10 values

I have a regex expression that traverses a string and pulls out 40 values, it looks sort if like the query below, but much larger and more complicated est(.*)/test>test>(.*)<test><test>(.*)test><test>(.*)/test><test>(.*)/test><test>(.*)/test><test(.*)/test><test>(.*)/test><test>(.*)/test><test>(.*)/test><test>(.*)/test><test>(.*)/test><...

How the Java equivalent to this preg_replace?

<?php $str = "word <a href=\"word\">word</word>word word"; $str = preg_replace("/word(?!([^<]+)?>)/i","repl",$str); echo $str; # repl <word word="word">repl</word> ?> source: http://pureform.wordpress.com/2008/01/04/matching-a-word-characters-outside-of-html-tags/ Unfortunality my project needs a semantic libs avaliabl...

HTML span tag content and attribute preg_match regular expressions

Hello, Does anyone have a fix for the following; I'm taking the following string: <span id="tmpl_main_lblWord" class="randomWord">kid</span> and using the following preg_match / regex rule; preg_match("'/(<span id=.* class=.*>)(.*)(<\/span>)/'si", $buffer, $match); But its returning with an empty array any ideas? ...

Regex in c# question

Hi there, been trying the to figure out the escape char for "["and "]" in regex. I have the following pattern of string and this string is the actual string: [somestring][anotherstring] So the string will start with "[" followed by somestring and followed by with "]" and followed by "[" and followed by anotherstring and followed by "]...

Is there Match Or Exception Regex in .NET

I would like to do something like the below but throw an exception because there is no match. Is that possible? var val = Regex.Match("nomatchplz", "notgoingtomatch(.*)").Groups[1].Value; ...

php find snippet of content from preg_match

Ok say I have a paragraph of text: After getting cut for the first and last time in his life, Durant watched from the sofa as the American team waltzed into the gold-medal game and then was tested by Spain, ultimately emerging with a 118-107 victory that ended an eight-year gold-medal drought for the senior U.S. men's n...

Ignore files in Mercurial using Glob syntax

I'm using Mercurial and I have a following structure: files test demo.jpg video.flv video.doc sport demo2.jpg picture.jpg text.txt demo3.jpg demofile3.doc I want to make a glob filter that only ignore all "jpg" files in all directory that are children of "files" directory I tried with ...

Which regexp php is using for filter_var($url, FILTER_VALIDATE_URL)?

Hello, filter_var($url, FILTER_VALIDATE_URL) seems to be great way to detect if $url contains url or not. Is there any way to see what regular expression this function uses for detecting? Thank you ...

Regex with can be numerous ----- and must newline after the string

How would a regex look like when I search for this string: before CAN be many comment lines --------"Encrypted" after must come a newline. this does not seem to work: Regex pattern = new Regex(@"^[-]*$[Encrypted][\n]"); what do I wrong? ...