regex

Removing backslashes from a string in Python

How do I remove all the backslashes from a string in Python? This is not working for me: result = result.replace("\\", result) Do I need to treat result as a raw string? ...

how to match a URL inside a HTML comment with regular expressions?

I'm making an automated script with PHP to check if my link exists at my partner website ( link exchange) .. besides making sure my link exists in the source code , I want to make sure he is not placing it in a HTML comment like <!-- http://www.mywebsite.com --> and cheating me .. I tried to match it with REGEXP , but have failed ...

regular expression to match files

hi all I used the following RE: ^file(\d{1,3})(\w*)(?:\.(\d{0,3})(\w*))? To match the following file1.bla or file1.1 or file1.1.bla but after: ls "^file(\d{1,3})(\w*)(?:\.(\d{0,3})(\w*))?" I not see any match of the relevant files why? Yael ...

How to automatically insert predefined text into a string in positions definable by a regular expression

I'd like to use javascript to search a string and automatically insert a closing tag before every occurrence of an opening tag. Here is the test code I've come up with so far: var str="<span>this <i>is</i> a <i>test</i></span>"; var patt1=/<(?!span)\b\w+>/g; var patt2=/<\/(?!span)\b\w+>/g; document.write(str.replace(patt1, '</b>' + str...

Regular expression help in PHP

I need help again with some regular expressions I'm trying to do (still under heavy learning). Again I'm trying to learn by parsing user agents. Trying to do Firefox now... Take in consideration these UAs: Mozilla/5.0 (Windows; U; Windows NT 6.0; de; rv:1.9.0.15) Gecko/2009101601 Firefox 2.1 (.NET CLR 3.5.30729) Mozilla/5.0 (X11; U; ...

Is there a regular expression optimizer in PHP?

Perl has Regexp::Optimizer, is there anything similar in PHP? My searches haven't turned up anything. For example, Regexp::Optimizer would turn /foobar|fooxar|foozap/ into /foo(?:[bx]ar|zap)/ Update: I wanted to keep that question really short so that people would not try to over-interpret it but it turns out it had the opposite...

Regex in rails to match [\w] and "-" but not numbers

Hello , I want to write a regular expression for First name validation . The regular expression should include all alphabets (latin/french/german characters etc.). However I want to exclude numbers from it and also allow -. So basically it is \w (minus) numbers (plus) -. Please help. ...

regex for sepcifying empty string in java

i dont know how to generate a regex that can represent empty string in java ...

Regular Expressions for Linux - scan the Apache HTTPD access log for all the response code other than 200

Hi. This is a question about grep and regular expression. If I want to see all the requests whose response is a 200 code, I can do: grep -e '^.* - - .* .* .* .* .* 200' access_log Quite easy peasy. But what if I want to retrieve all the requests whose response is NOT a 200 code? I would like to be able to do that with only one grep...

find with -regex flag ti match files

hi all under /tmp directory I have the following files file1 file2 when I run the following find command with -regex , find command not match the files why? find /tmp -regex '/file(\d{1,3})/' ...

Javascript replace problems (with alt and title atribbutes )

Hi, i have the following code: function getArticleContent() { var toPromote = 'example'; var toReplace = '<a href="/tags/'+toPromote+'">'+toPromote+'</a>'; var content = $(".a-entry").text(); if (content.search(toPromote) > -1) { $('.a-entry').html($('.a-entry').html().replace(new RegExp(toPromo...

Capturing <thisPartOnly> and (thisPartOnly) with the same group

Let's say we have the following input: <amy> (bob) <carol) (dean> We also have the following regex: <(\w+)>|\((\w+)\) Now we get two matches (as seen on rubular.com): <amy> is a match, \1 captures amy, \2 fails (bob) is a match, \2 captures bob, \1 fails This regex does most of what we want, which are: It matches the open and...

Regular Expression to generate a string

I am using a tool to generate test data for our database. For columns that are string fields, we have the option of entering a regular expression that will be used to generate values for the column. I would like a regular expression that generates a 15 character string as follows: Characters 1-6 should consist of the YYMMDD (current ye...

Regular Expression Needed

I need a regular expression that matches a 15 character string as follows: Characters 1-6 should match '100702' Characters 7-8 should match '25' or '26' Characters 9-15 should match any digit (0-9) but must contain a digit. This is for .NET Thank you. ...

How can I test regexp and fetch matching parts in Ruby?

I have an input, which can have different structure. I would like to test few patterns and get corresponding matching parts in each case without repeating the regular expressions. For example: a = "hello123" case a when /^([0-9]+)([a-z]+)$/ # how to get matching values? when /^([a-z]+)([0-9]+)$/ # how to get matching values? else en...

removing every other character in a string using java regex

hi, i have this homework problem where i need to use regex to remove every other character in a string. in one part, i have to delete characters at index 1,3,5,.... i have done this as follows: String s = "1a2b3c4d5"; System.out.println(s.replaceAll("(.).", "$1")); this prints 12345 which is what i want. essentially i match two char...

python regex: match a string with only one instance of a character

Suppose there are two strings: $1 off delicious ham. $1 off delicious $5 ham. In Python, can I have a regex that matches when there is only one $ in the string? I.e., I want the RE to match on the first phrase, but not on the second. I tried something like: re.search(r"\$[0-9]+.*!(\$)","$1 off delicious $5 ham.") ..saying "Match ...

Find PHP with REGEX

I need a REGEX that can find blocks of PHP code in a file. For example: <? print '<?xml version="1.0" encoding="UTF-8"?>';?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <?php echo...

Minimum 6 characters regex expression

Minumum 6 letter checks textbox in asp.net. I m looking for all letters and numbers, but I need it for all characters. ...

Removing CRLF (0D 0A) from string in Perl

Hi All, I've got a Perl script which consumes an XML file on Linux and occasionally there are CRLF (Hex 0D0A, Dos new lines) in some of the node values which. The system which produces the XML file writes it all as a single line, and it looks as if it occasionally decides that this is too long and writes a CRLF into one of the data e...