regex

searching backwards with regex

I have the following different texts line1: SELECT column1, line2: column2, line3: RTRIM(LTRIM(blah1)) || ' ' || RTRIM(LTRIM(blah3)), line4: RTRIM(LTRIM(blah3)) || ' ' || RTRIM(LTRIM(some1)) outColumn, line5: RTRIM(LTRIM(blah3)) || ' ' || RTRIM(LTRIM(some1)) something, line6: somelast Following is what I want to get out of each line b...

.htaccess rules with a subdomain and two domains

I have a domain domain.com that I use as my primary domain. I also own a second domain domain2.com that I have automatically go to domain.com This is done with .htaccess: RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC] RewriteRule (.*) http://www.domain.com/$1 [L,R=301] I want to set up a subdomain sub.domain.com but with that curre...

using java regex how can I replace all when pattern contains left parenthesis

I have a string that looks like this: "mynum(1234) and mynum( 123) and mynum ( 12345 ) and lastly mynum(#123)" I want to insert a "#" in front of the numbers in parenthesis so I have: "mynum(#1234) and mynum( #123) and mynum ( #12345 ) and lastly mynum(#123)" How can I do this? Using regex pattern matcher and a replaceAll chokes on ...

In Perl is there a difference between /^/ and /^/m?

The documentation for the /m option in perlre says this: Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string. But this example seems to indicate that /^/ and /^/m behave the same way. What am I misunderst...

How do I replace all punctuation in my string with "" in Python?

If my string was: Business -- way's I'd like to turn this into: Business ways ie. replace NON abc/123 into "" ...

How to back reference "inner" selections ( () ) in a regular expression?

How do you back reference inner parenthesis in Regex? The sample data is a product price list showing different price breaks based on quantity purchased. The format is quantityLow - quantityHigh : pricePer ; multiples. I used LINQPad to construct this C# Regex expression to separate the parts, which shows a handy visualization of the ...

How to replace the quote " and hyphen character in a string with nothing in Python?

I'd like to replace " and - with "" nothing! make it disappear. s = re.sub(r'[^\w\s]', '', s) this makes all punctuation disappear, but I just want those 2 characters. Thanks. ...

The SHORTEST way to remove multiple spaces in a string in Python

Suppose this is the string: The fox jumped over the log. It would result in: The fox jumped over the log. What is the simplest, 1-2 liner that can do this? Without splitting and going into lists... ...

Javascript Regex Browser Inconsistancy?

I have a regex that I am using in an asp.net RegularExpressionValidator to check a TextField. ^(?=.*[a-z])(?=.*\d)(?=.*[A-Z]).{8,}$ The example string I have stumbled on is 'RedCoal1' Firefox = Matched IE8 = Matched Chrome = Matched IE7 = DOES NOT MATCH WHY!!!! ...

RegEx for Prices?

Hi Chaps, I am searching for a RegEx for prices. So it should be X numbers in front, than a "," and at the end 2 numbers max. Can someone support me and post it please? ...

Restricting text box inputs to a given regexp using jQuery

Consider the following text box: <input type="text" name="quantity" id="quantity_field" /> Using jQuery I want to restrict the set of valid inputs into quantity_field by the following regexp: <script> var quantityRegexp = "^(0|[1-9]+[0-9]*)$"; </script> More specifically I want to make the browser discard any characters entered ...

Regular expression substitution for ENUM record

How do I susbtitute in matched groups from 1 regular expression into another regular expression in C#? I need to process an ENUM DNS record where the first half of the record is a regular expression to apply to the lookup value and the second half is a regular expression that uses the matches from the first. Example of an ENUM record f...

Java Scanner Delimiter Usage

I'd like to specify a delimiter for a scanner that splits on some pattern, but doesn't remove that pattern from the tokens. I can't seem to make this work, as anything that is identified by the regex also gets eaten as part of the delimiter. Any suggestions? My specific problem, I have file that looks like: text/numbers mix numbers n...

.htaccess rewrite regex: match anything but "index"

Hi guys and gals, I'm trying to create a rule used in a .htaccess file to match anything but a particular string, in this case: index. I thought that it should be possible to match this special string first and use [L] but that's not working, and it should be possible using the following regex, but it causes a 500 error. I want to mat...

How can I match the domain part of a URL in PHP?

I'm so bad at regexp, but I'm trying to get some/path/image.jpg out of http://somepage.com/some/...etc and trying this method: function removeDomain($string) { return preg_replace("/http:\/\/.*\//", "", $string); } It isn't working -- so far as I can tell it's just returning a blank string. How do I write this regexp? ...

Regex From .NET to Python

I have a regular expression which works perfectly well (although I am sure it is weak) in .NET/C#: ((^|\s))(?<tag>\@(?<tagname>(\w|\+)+))(?($|\s|\.)) I am trying to move it over to Python, but I seem to be running into a formatting issue (invalid expression exception). It is a lame question/request, but I have been staring at this fo...

Mysql text extract with Regex

Hi, i try to extract text from html text stored in a db. This is an example: <P style="FONT-SIZE: 13px; MARGIN-LEFT: 6px"><FONT color=#073b66><STRONG><A href="/generic.asp?page_id=p00497">Practice Exams</A> - </STRONG><FONT color=#000000>ours are the most realistic exam simulations, and the best way to prepare for your exams. Get de...

How can I find all matches of '{{**** *** **}}' with a regex?

I'm trying to extend PHP Markdown to allow the use of {{ and }} around some parts of the text (they will become search keywords, like a tag). I have this basic regex that kinda works: preg_match_all("/\{\{(.*)\}\}/", $description, $nomsTags); Except it doesn't work when there are 2 keywords in the same sentence: This {{is}} just an ...

Sort lines on webpage using javascript/ regex

I'd like to write a Greasemonkey script that requires finding lines ending with a string ("copies.") & sorting those lines based on the number preceding that string. The page I'm looking to modify does not use tables unfortunately, just the br/ tag, so I assume that this will involve Regex: http://www.publishersweekly.com/article/CA659...

How can I find all matches of <element>something</element> with a regex?

So let's say that I have: <any_html_element>maybe some whitespaces <br/>Some text</any_html_element> And I want to remove the first <br/> after <any_html_element>. How can I do that? Best Regards ...