regex

Java regex to match "t" except when it's "[t" or "t]"

I'm using replaceAll() on a string to replace any letter with "[two letters]". So xxxaxxx to xxx[ab]xxx. I don't want the ones that have already been replaced to be done again (turns to xxx[a[cb]]xxx)... An easy way to do this would be to exclude any letters that are proceded by a "[" or followed by "]". What's the correct Regex to use?...

How to remove a tag, and preserved the text in the element using RegExp?

Hi, I want to remove the element tag and want to preserve the text inside the tag. I use the replace function of RegExp but it removed everything: The tag and the text inside the tag. I dont want that, I want to remove the tag only. Clean up the text, remove the tags, I want to present the text only. var str = str.replace(/<.>[^.]*\/.>...

RegExp: I want to remove unnecessary words in the Sentence. How can I do it?

I have a sentence, and I want to remove some words from it. So if I have: "jQuery is a Unique language" and an array that is named garbageStrings: var garbageStrings = ['of', 'the', "in", "on", "at", "to", "a", "is"]; I want to remove the "is" and "a" in the sentence. But if I use this: /This statement is inside a for loop. I'm l...

Checking version number validity with Perl

I'm struggling with checking the validity of version numbers in Perl. Correct version number is like this: Starts with either v or ver, After that a number, if it is 0, then no other numbers are allowed in this part (e.g. 10, 3993 and 0 are ok, 01 is not), After that a full stop, a number, full stop, number, full stop and number. I.e...

Regex match spaces in html attribute

I have a bunch of html with lines like this: <a href="#" rel="this is a test"> I need to replace the spaces in the rel-attribute with underscores, but I'm sort of a regex-noob! I'm using Textmate. Can anyone help me? /Jakob ...

What is the expression on RegularExpressionValidator to check if the Textbox text is 6 or more characters long?

Hello guys, what is the format for the RegularExpressionValidator control to check if the textbox to be validated has 6 or more characters? ...

Regular expression to count number of , in string

Can anyone help me build a regular expression that will find a string of any length containing any characters but must contain 21 commas Thanks ...

php non-greedy regex problem

demo: $str = 'bcs >Hello >If see below!'; $repstr = preg_replace('/>[A-Z0-9].*?see below[^,\.<]*/','',$str); echo $repstr; What I want this tiny programme to output is "bcs >Hello ",but in fact it's only "bcs " What's wrong with my pattern? ...

Regular expression to retrieve domain.tld

I'm need a regular expression in Java that I can use to retrieve the domain.tld part from any url. So https://foo.com/bar, http://www.foo.com#bar, http://bar.foo.com will all return foo.com. I wrote this regex, but it's matching the whole url Pattern.compile("[.]?.*[.x][a-z]{2,3}"); I'm not sure I'm matching the "." character right....

Auto-selection of <option> based on input field, with some caveats

I have a SELECT element in which I need to auto-select the appropriate option based on the first half of a postcode entered in a text field. British postcodes are of the form AB12 3CD, where the first section consists of 1-2 letters representing the county and a number representing the area within the county. The last 3 characters are ir...

How to reject names (people and companies) using whitelists with C# regex's?

I've run into a few problems using a C# regex to implement a whitelist of allowed characters on web inputs. I am trying to avoid SQL injection and XSS attacks. I've read that whitelists of the allowable characters are the way to go. The inputs are people names and company names. Some of the problems are: Company names that have amper...

Using BeautifulSoup to find a HTML tag that contains certain text

I'm trying to get the elements in an HTML doc that contain the following pattern of text: #\S{11} <h2> this is cool #12345678901 </h2> So, the previous would match by using: soup('h2',text=re.compile(r' #\S{11}')) And the results would be something like: [u'blahblah #223409823523', u'thisisinteresting #293845023984'] I'm able to...

Regex to match www.example.com only if http:// not present

I have the following regex that isn't working. I want to match the string 'www.example.com' but not the string 'http://www.example.com' (or 'anythingwww.example.com' for that matter): /\bwww\.\w.\w/ig This is used in JavaScript like this: text = text.replace(/\bwww\.\w.\w/ig, 'http://$&amp;'); I know the second part of the regex do...

regular expressions: match x times OR y times

Lets say I need to match a pattern if it appears 3 or 6 times in a row. The closest I can get is something like \d{3,6} but that doesn't quite do what I need. '123' should match '123456' should match '1234' should not match ...

regular expression for non consecutive characters

If a language consists of set {a, b, c} only how can we construct a regular expression for the langage in which no two consecutive characters appear. eg: abcbcabc will be valid and aabbcc will rejected by the regular expression. ...

Regular expression to define some binary sequence

How would you write a regular expression to define all strings of 0's and 1's that, as a binary number, represent an integer that is multiple of 3. Some valid binary numbers would be: 11 110 1001 1100 1111 ...

vim & csv file: put header info into a new column

I have a large number of csv files that look like this below: xxxxxxxx xxxxx Shipment,YD564n xxxxxxxxx xxxxx 1,RR1760 2,HI3503 3,HI4084 4,HI1824 I need to make them look like the following: xxxxxxxx xxxxx Shipment,YD564n xxxxxxxxx xxxxx YD564n,1,RR1760 YD564n,2,HI3503 YD564n,3,HI4084 YD564n,4,HI1824 YD564n is a sh...

Is RegEx from user input safe?

I'm working on an app that needs to accept a RegEx from the user, to do so I'm using the following code: Regex user_searchPattern = new Regex(this.userInput_regEx.Text); Is doing this safe? Is there a need to sanitize the user input, and if so how? ...

Regular Expression to Detect and Update String ( Useful to Update File Version in AssemblyInfo.cs)

I have a string of this format 1.0.x.0 I have to write a regex in javascript that automatically increment the x-- How to do it? Note, the string given will always be of that format-- no need to test for format validity... ...

Can u tell me the regular expression for finding the image url in <img> tag in HTML using VB .Net code

Hi I want to extract the image url from any website. I am reading the source info through webRequest. I want a regular expression which will fetch the Image url from this content i.e the Src value in the tag. Thanks ...