regex

Regex to not match tab, carriage return and square brackets

I need a regex to not match tab, carriage return and square brackets. (C#) ...

Where to store Regex?

When you are using a Regex instance, that is used in a method where that method is called a couple thousand times to parse things in a certain way, should that method include the Regex instance, or should the Regex instance be part of the class as a static member? I get the feeling that initializing the same Regex thousands of times mig...

Javascript regex: How to extract an "id" from a string?

I have this string: comment_1234 I want to extract the 1234 from the string. How can I do that? Update: I can't get any of your answers to work...Is there a problem with my code? The alert never gets called: var nameValue = dojo.query('#Comments .Comment:last-child > a[name]').attr('name'); alert('name value: ' + nameValue); // comme...

.NET regex decimal numbers

I have to validate using regex decimal number between 00.00 to 35.35 with following simple assumptions(I am using C#). 1) leading zeros are not required(optional). 2) 2 decimals are always required. In other words, it should be a decimal number within a range with 2 decimal points. Examples of valid numbers are: 0.00, 00.00, .67, 2.8...

How to write regex that searches for a dynamic amount of pairs?

Lets say a have a string such as this one: string txt = "Lore ipsum {{abc|prop1=\"asd\";prop2=\"bcd\";}} asd lore ipsum"; The information I want to extract "abc" and pairs like ("prop1","asd") , ("prop3", "bcd") where each pair used a ; as delimeter. Edit1: (based on MikeB's) code Ah, getting close. I found out how to parse the fol...

Jmeter - get entire query string into variable

Is there a way to use the Regular Expression Extractor to grab the entire .NET encrypted query string and place it in a variable? Example, for URL via a GET: https:/www.website.com/folder/page.aspx?jfhjHSDjgdjhsjhsdhjSJHWed I am trying to have ${myQueryString} = jfhjHSDjgdjhsjhsdhjSJHWed so I can replay it later in the test plan by ...

Help to find Reg-ex usage errors.

Hello, I want to cach input, which seems to be like SQL injection. I know now, that Reg-ex usage for finding SQL-injections is not a best way, but i simply need to do some researcha about it and I'm asking for help to fix some errors. So I wrote the method: public static bool IsInjection(string inputText) { bool isInj = false; ...

Regex to remove starting and ending string

I am working on a small app where I need to remove the starting and ending tags and I am having a little trouble getting the expression right. Currently I have this bit of code. The issue is on the second output, nothing is displayed. <cfcontent reset="true"/> <cfset myStr = '<br> <br> <br> <br> This is a great Test<br> do you like my...

PHP regex for validating a URL

Hi, I'm looking for a decent regex to match a URL (a full URL with scheme, domain, path etc.) I would normally use filter_var but I can't in this case as I have to support PHP<5.2! I've searched the web but can't find anything that I'm confident will be fool-proof, and all I can find on SO is people saying to use filter_var. Does anybo...

Regular expression, find a word between two words

hello all, I have this string <p/><ul><li>test1<p/></li><li>test2<p/></li></ul><p/> What i attempt to do is extract all the "p" tag within the "li" tag, but not the "p" tag outside of it. I'm only able so far to extract all the "li" tags by \<li\>(.*?)\</li\> I'm lost at how to extract the "p" tag within it. Any pointer is grea...

Regex + Python to remove specific trailing and ending characters from value in tab delimited file

It's been years (and years) since I've done any regex, so turning to experts on here since it's likely a trivial exercise :) I have a tab delimited file and on each line I have a certain fields that have values such as: foo bar b"foo's bar" b'bar foo' b'carbar' (A complete line in the file might be something like: 123\t b'bar foo'...

Best way to substract form input fields html

How would you best get all the input fields (text, radiobutton, checkbox, select etc) semi-automatically out of dodgy formatted html documents? Trying to get the TYPE,NAME,VALUE and OPTION for SELECT. I am currently using Xpath (in PHP) because everyone here says 'use that instead' but I'm getting nowhere with it. So I am open to sugge...

.NET Regular expression for querystring value

I need to strip out any "&id=SomeValue" from a Url.PathAndQuery. Where SomeValue could be an int or a string. And it may or may not be followed by another ampersand. So it could be somepage.aspx?cat=22&id=SomeId&param2=4 or somepage.aspx?cat=tect&id=450 I want to be left with somepage.aspx?cat=22&param2=4 or somepage.aspx?ca...

Extract the surrounding words together with the match

I am looking for every occurence of a search term, e.g. ddd, in a file and output the surroundings, like this: File.txt aaa bbb ccc ddd eee fff ttt uuu iii eee ddd ddd ggg jjj kkk ddd lll output ccc ddd eee eee ddd ddd kkk ddd lll As a starting point, I am using this piece of code #!/usr/bin/perl -w while(<>) { while (/...

How to Regex international alphabet (english a-z, + non english)

Hello, I want to allow only entered data from the English alphabet and from alphabet from Germany like öäü OR France like áê or Chinese like ... How can I configure my Regex so it accepts all alphabetical chars from internal alphabet? ...

Combining Codeigniter routes with regex

Hi, I've been playing around with creating an e-commerce site with Codeigniter, and am trying to do the following: Have category names as the first parameter, e.g. /tshirts /shoes following each of these, is either a filter (on the category), or the product (with category in URL for SEO) /tshirts/filter/price/0-20 /tshirts/pink-wi...

Small regex question in PHP

Hi, I'm trying everything in a string BUT a certain pattern. My pattern is: $pattern = "/^[a-zA-Z0-9]+$/D"; And I want to do the following: $string = preg_replace(anything but $pattern, "", $string); How do I do that? Thanks! ...

How do I strip all html tags in javascript with exceptions?

I've been beating my head against this reg ex for the longest time now and am hoping someone can help. Basically I have a WYSIWYG field where a user can type formatted text. But of course they will copy and paste form word/web/etc. So i have a JS fucntion catching the input on paste. I got a function that will strip ALL of the format...

Regular expression to find text not part of a hyperlink

I'm trying to find a single regular expression that I can use to parse a block of HTML to find some specific text, but only if that text is not part of an existing hyperlink. I want to turn the non-links into links, which is easy, but identifying the non-linked ones with a single expression seems more troublesome. In the following exam...

Regex that ignores double-quoted sections

I'm trying to write a regular expression (via Autohotkey's RegExReplace function) that will enforce variable casing in exported VBA code as a preprocessing step to version control. So if I want all case-insensitive occurrences of 'firstName' to be changed to match that case then the following line: If FirstName = "" Then MsgBox "Please...