regex

Regular expression pattern help

Trying to find "\[" in my content don't get any results. I use this pattern: preg_replace('/\\\[/', $content, $matches); What's wrong whith my pattern? Thank you. Update. My fault, I meant preg_match_all. ...

Regex: How to not match the last character of a word?

I am trying to create a regex that does not match a word (a-z only) if the word has a : on the end but otherwise matches it. However, this word is in the middle of a larger regex and so I (don't think) you can use a negative lookbehind and the $ metacharacter. I tried this negative lookahead instead: ([a-z]+)(?!:) but this test case ...

Regex to limit string length for strings with new line characters

Hi, Looks like a simple task - get a regex that tests a string for particular length: ^.{1,500}$ But if a string has "\r\n" than the above match always fails! How should the correct regex look like to accept new line characters as part of the string? I have a <asp:TextBox TextMode="Multiline"> and use a RegularExpressionValidator to...

What's wrong with my REGEX while using VI editor?

I have a text document like so: <table width="10"> </table> I open the document with the VI editor. I want to replace all instances of width="somenumber" with nothing. I issue this command in the VI editor: :0,$s/width="[\d]+"//gc VI says no pattern found. I also tried this and it doens't work: 0,$s/width="[0-9]+"//gc This o...

Quotes inside ValidationExpression for RegularExpressionValidator

Using said control to validate a ASP.NET TextBox, I'm curious what the most popular practice is. Currently using: ValidationExpression="^[\w\d\s.,&quot;'-]+$" Any shorter way of doing this? Tried \ , "" to no avail. Thanks. ...

Regex with Tab delimited text containing \x09

I've got a tough one. I've got tab-delimited text to match with a regex. My regex looks like: ^([\w ]+)\t(\d*)\t(\d+)\t([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)$ and an example source text is (tabs converted to \t for clarity): JJ\t345\t0\tTest\tSome test text\tmore text: pcre:"/\x20\x62\x3b\x0a\x09\x61\x2e\x53\x74\x61\x72/"\tNone ...

need a regex to match URL (without http, https, ftp)

just need a regex to match URLs without http , https, ftp in the beginning. basically i need it for mod rewrite examples: www.someurl.com/blah/blah/balh/etc/and/so/on crazy.something.net/agjja something.us/index.php? so i can do RewriteCond %{REQUEST_URI} URLregexhere RewriteRule ^URLregexhere$ ping.php?url=$1 [L] ...

Efficient way to compare two strings (ordering of characters irrelevant)

I am trying to come up with an algorithm to compare two strings. It would register a match any words that contain the same letters. For example rent and tern would be equivalent because they both contain the letters r,e,n,t. EDIT I apologize for being so vague. The comparison is going to be made on two sets of a few thousands of words h...

regular expression in python

Hi I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or split?? Thanks ...

Parsing css with a regex

I'm wanting to scan through a css file and capture both comments and the css. I've came up with a regex that's almost there, however it's not quite perfect as it misses out properties with multiple declarations i.e. ul.menu li a, # Won't capture this line ul.nice-menu li a { text-decoration: none; cursor:pointer; } Here's the regex th...

ISAPI Rewrite rule help (http://www.foo.com/bar --> http://www.foo.com/bar.aspx)

A really easy one, but I need to get this right, and cannot afford mistakes as I need to deploy on a live server as soon as I can. http://www.foo.com/bar --> http://www.foo.com/bar.aspx http://www.foo.com/bar?q=boo --> http://www.foo.com/bar.aspx?q=boo # I only want /bar to get rewritten to /bar.aspx # everything else stays as is http...

Using Python Regular Expression in Django.

I have an web address: http://www.example.com/org/companyA I want to be able to pass CompanyA to a view using regular expressions. This is what I have: (r'^org/?P<company_name>\w+/$',"orgman.views.orgman") and it doesn't match. Ideally all URL's that look like example.com/org/X would pass x to the view. Thanks in advance! ...

Which regular expression api would you emulate?

Most programming languages have apis for regular expression searching and replacing. In my experience the apis can be quite clunky, probably due to the number of actions available and efficiency considerations. If you were going to implement an api, which one would you emulate? Of particular interest is the methods and objects of the a...

Specify glob size range in Regex

How do I define a minimum and maximum (possibly unbounded) number of times a certain pattern should repeat itself? I know there's ? and *, with which I could build the pattern by repeating it a certain amount of times, but I know there's a special notation for it using {}, I just can't remember how it is. ...

Inline SED regular expression question

I work for a company that offers webhosting and DNS services. We are trying to migrate everything over to new servers and we've often run into stale zonefiles on our servers as customers have changed their authoritative servers to someone else. I am trying to write a script that will check whois, ns, and SOA information to determine if...

Regex replace/search using values/variables in search text

What is the regex syntax to use part of a matched expression in the subsequent part of the search? So, for example, if I have: "{marker=1}some text{/marker=1}" or "{marker=2}some text{/marker=2}" I want to use the first digit found in the pattern to find the second digit. So in "{marker=1}{marker=2}some text{/marker=2}{/marker=1}" the ...

Python RegEx skipping the first few characters?

Hey I have a fairly basic question about regular expressions. I want to just return the text inside (and including) the body tags, and I know the following isn't right because it'll also match all the characters before the opening body tag. I was wondering how you would go about skipping those? x = re.match('(.*<body).*?(</body>)', file...

How do I match a text which can contain - or an underscore using regular expression?

I want the username to be any characters with _ or - in it but this in Perl is not working, why is it? if ("kunjaaN-" =~ /^[a-zA-Z-_]{1,7}$/) { print "equal" ; } ...

White listing certain HTML tags in python?

Let's say allowed_bits = ['a', 'p'] re.compile(r'<(%s)[^>]*(/>|.*?</\1>)' % ('|'.join(allowed_bits))) matches: <a href="blah blah">blah</a> <p /> and not: <html>blah blah blah</html> What I want to do is turn it on its head, so that it matches <html>blah blah</html> <script type="text/javascript">blah blah</script> and not: ...

regular expression for words beginning with a certain string (javascript)

I am trying to write a regular expression in javascript for finding if any words in a sentence start with a particular phrase. Eg, I'd like to know if "by" is contained at the beginning of any word in the following sentence : "The Tipping Point by Malcolm Gladwell". I tried using \b but /\bsor/ will match a sentence like 'Mary's organ ...