regex

help needed to create Regular expression

need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card it can be anyhing like us, uk or com, edu like www.us.abc.com/somestring www.uk.abc.edu/somestring ...

Preg Match circumflex ^ in php

I cant quite get my head around what the ^ is doing in my preg_match. if (preg_match('~^(\d\d\d\d)(-(\d{1,2})(-(\d{1,2}))?)?$~', trim($date), $dateParts)) { echo the $dateparts and do some magic with them } else { tell me the date is formatted wrong } As I see it this is looking to see if the $date matches the format which I ...

REGEXP not working for ' (apostrophe) and -(dash) in mysql

I'm using REGEXP for search in a MySQL DB, but it is not returning the proper data when I insert ' (apostrophe) and - (dash) in the search query. Is there any solution to this? Here is the full query: select * from table where (field REGEXP 'SAN DIEGO | SAN DIEGO |^SAN DIEGO' or field2 REGEXP 'SAN DIEGO | SAN DIEGO |^SAN DIEGO' ) ...

Add Suffix To All Internal URLs

I need to add a suffix of ?hl=foo to the end of all internal URLs on my site. Im not sure of the best way to do this because of complications such as... <a href="http://www.example.com"&gt;My Site</a> <a target="_blank" href="http://www.example.com"&gt;My Site</a> <a class="a-class" href="http://www.example.com"&gt;My Site</a> ...

Specific domain URL validation with Regular Expression

I've been trying myself, and searching online, to write this regular expression but without success. I need to validate that a given URL is from a specific domain and a well-formed link (in PHP). For example: Good Domain: example.com So good URLs from example.com: http://example.com/so/this/is/good http://example.com/so/this/is/good...

What flavour of regular expression is grep?

I'm guessing it's not a Perl compatible regular expression, since there's a special kind of grep which is specifically PCRE. What's grep most similar to? Are there any special quirks of grep that I need to know about? (I'm used to Perl and the preg functions in PHP) ...

What manner of regular expression might I use to add line breaks near HTML tags?

I have the following regular expression which is used to give me the tags in the HTML string: <[^>]*> So, if I pass in the following: <b> Bold </b> Then it will give me: <b> </b> How can I make it to give me: <b> Bold </b> UPDATE: Here is another example to get the big picture: If this is the text: <b>Bold</b> This ...

How to construct this in regular expression

I want to match the pattern: Starts with 0 or more spaces, followed by "ABC", then followed by anything. So things like " ABC " " ABC111111" "ABC" would be matched. But things like " AABC" "SABC" would not be matched. I tried: String Pattern = "^\\s*ABC(.*)"; But it does not work. Any ideas? This is in C# by the way. ...

In JavaScript, are regular expressions evaluated in compiled code?

When a regular expression is run JavaScript, is the regex engine that evaluates the expression compiled code? or the engine itself is written in javascript? While doing some basic string matches tests, I found that a single regex is considerably faster than my JavaScript function that does the same thing, so I wondered why the regular e...

Regex replace between multiple paragraphs (.Net)

Hi, it’s been a while since the last time I had to use regex, I am kind of in a hurry to accomplish something so I hope I can get a quick answer to this quick question. Say I have the following text: Start A B C End Start A B C End Start A B C End Foo A B C Bar I would like to replace the line breaks with pipes but only between t...

capture part of a string with regex using PHP?

I can't seem to find a function that captures and returns a regex'ed string. $string = "hello123!"; $string = regexfunction($string, "/([0-9]*)/"); echo $string; Prints 123 ...

What's wrong with this RegEx for validating emails?

Here's a regex for validating emails - \S+@\S+\.\S+, I didn't write it. I'm new to Regular Expressions and do not understand them all that well. I have a couple of questions: What's wrong with the above RegEx? What's a good RegEx for validating emails? Thanks in advance. ...

Apache: Block all directories except for listed ones

I want to block people from accessing every directory except for /sandbox, /WebDev and /Projects I tried this: <Directory ^/(?<!sandbox|Projects|WebDev)+(/.*)> Order Deny,Allow Deny from all </Directory> but it gave a 500 error. ...

How do I split a string using a regular expression that excludes an escaped version of my token?

In Java, I'm using the String split method to split a string containing values separated by semicolons. Currently, I have the following line that works in 99% of all cases. String[] fields = optionsTxt.split(";"); However, the requirement has been added to include escaped semicolons as part of the string. So, the following strings sh...

Regular expression joke explanation

I love regex. I’ve used them with grep, Perl, Java, C, and a variety of others. I have Jeffery Friedl’s awesome book on them, and I studied their theory in college. But for years I have been haunted by a famous regex joke: Q: What did one regular expression say to the other? A: .* which I first saw on Slashdot, years ago. ...

replace exact match in php

im new to regular expressions in php. I have some data in which some of the values are stored as zero(0).What i want to do is to replace them with '-'. I dont know which value will get zero as my database table gets updated daily thats why i have to place that replace thing on all the data. $r_val=preg_replace('/(0)/','-',$r_val); Th...

C# Check a word exists in a string

Is the best way to do this with Regex? I don't want it picking up partial words for example if I'm search for Gav it shouldn't match Gavin. Any examples would be great as my regular expression skills are non existant. Thanks ...

pattern match java: does not work

hey everyone, i am trying to find a certain tag in a html-page with java. all i know is what kind of tag (div, span ...) and the id ... i dunno how it looks, how many whitespaces are where or what else is in the tag ... so i thought about using pattern matching and i have the following code: // <tag[any character may be there or not]id...

How can I search for simple if statements in C source code?

I'd like to do a search for simple if statements in a collection of C source files. These are statements of the form: if (condition) statement; Any amount of white space or other sequences (e.g. "} else ") might appear on the same line before the if. Comments may appear between the "if (condition)" and "statement;". I want to ex...

How to emulate language complement operator in .hgignore?

I have a Python regular expression that matches a set of filenames. How to change it so that I can use it in Mercurial's .hgignore file to ignore files that do not match the expression? Full story: I have a big source tree with *.ml files scattered everywhere. I want to put them into a new repository. There are other, less important fil...