regex

boost::regex behaving differently on debug and release builds

boost::regex re("^\\s*([_\\w\\.]+)\\s*=\\s*([^\\s]+)$"); if(re.empty()){ std::cout<<"How is this possible?"<<std::endl; } That line prints in my release builds! (The debug builds are fine) Working with MSVC 2008 (vc 9.0) Compiler options for DEBUG: /Od /I "C:\Program Files\boost\boost_1_44_0" /I "C:\gtest-1.5.0\include" /I "includ...

How do I restrict a string to a specific set of characters in JavaScript?

To put this in context, consider these 2 functions: ml_RestrictToChars = function(input,regex) { var result = '';var c = ''; var rx = new RegExp(regex); for (var i = 0; i < input.length; i++) { c = input.charAt(i); if (rx.test(c)) { result += c; } } return result; }; ml_OmitChars =...

Java regex confusion

I have the following (Java) code: public class TestBlah { private static final String PATTERN = ".*\\$\\{[.a-zA-Z0-9]+\\}.*"; public static void main(String[] s) throws IOException { String st = "foo ${bar}\n"; System.out.println(st.matches(PATTERN)); System.out.println(Pattern.compile(PATTERN).matcher(...

preg_replace on the matches of another preg_replace

I have a feeling that I might be missing something very basic. Anyways heres the scenario: I'm using preg_replace to convert ===inputA===inputB=== to <a href="inputB">inputA</a> This is what I'm using $new = preg_replace('/===(.*?)===(.*?)===/', '<a href="$2">$1</a>', $old); Its working fine alright, but I also need to further re...

REGEX: Capture Filename from URL without file extention

So I am trying to create a Javascript Regex that captures the filename without the file extension. I have read the other posts here and 'goto this page: http://gunblad3.blogspot.com/2008/05/uri-url-parsing.html' seems to be the default answer. This doesn't seem to do the job for me. So here is how I'm trying to get the regex to work: ...

Using a regex as a template with Python

I have the idea to use a regex pattern as a template and wonder if there is a convenient way to do so in Python (3 or newer). import re pattern = re.compile("/something/(?P<id>.*)") pattern.populate(id=1) # that is what I'm looking for should result in /something/1 ...

Javascript Regex - Camel to File Case

Anyone have a regex in javascript for converting: someCamelCase into some-file-case or SomeCamelCase into some-file-case ?? If so, that would be very helpful. Thanks. ...

python: replacing regex with BNF or pyparsing

I am parsing a relatively simple text, where each line describes a game unit. I have little knowledge of parsing techniques, so I used the following ad hoc solution: class Unit: # rules is an ordered dictionary of tagged regex that is intended to be applied in the given order # the group named V would correspond to the value (if...

javascript dynamic regex vs hard typed and captures

I've been at this for hours -- I think I need sleep... but no matter how I alter the expression javascript will only capture the 1st and 3rd elements: var number = 09416; var mat = "([0-9]+/[0-9]+/[0-9]+\\s+[0-9]+:[0-9]+)\\s+([A-Z]+)\\s+[0-9,]+\\s+(.*?"+number+".+)"; // month / day / year hour : min AMPM byte...

Javascript: Declare variables from RegEx, write to cookie.

This question has two parts. First, I need to isolate two strings of text inside a span with the class "test01". Here is what the span looks like: <span class="test01"> <table width="100%" cellspacing="0" cellpadding="0"> <tbody><tr><td> <div id="ctl00_ctl07_pnTopBar"> <a href="/Member/MyHome.aspx">My Account</a>&nbsp;&nbsp;<a ...

How would I implement this regex in ColdFusion (or Java)?

I found this very handy regular expression on regexlib.com, but i'm at a loss as to how to implement it in my app. (?:(?:(?<Feet>\d+)[ ]*(?:'|ft)){0,1}[ ]*(?<Inches>\d*(?![/\w])){0,1}(?:[ ,\-]){0,1}(?<Fraction>(?<FracNum>\d*)\/(?<FracDem>\d*)){0,1}(?<Decimal>\.\d*){0,1}(?:\x22| in))|(?:(?<Feet>\d+)[ ]*(?:'|ft)[ ]*){1} I tested it out ...

regex regarding symbols in urls

Hi guys, I want to replace consecutive symbols just one such as; this is a dog??? to this is a dog? I'm using str = re.sub("([^\s\w])(\s*\1)+", "\\1",str) however I notice that this might replace symbols in urls that might happen in my text. like http://example.com/this--is-a-page.html Can someone give me some advice h...

Regex html tags

I'm trying to figure out the regex for the following: String</td><td>[number 0-100]%</td><td>[number 0-100]%</td><td>String</td><td>String</td> Also, some of these td tags may have style attributes at some point. I tried this: String<.*> and that returned String</td> but trying String<.*><.*> returned nothing. Why is this? ...

Java text parsing help needed with section name/content text

I have text in the following format: section name 1: this text goes into the first section section name 2: this text goes into the second section etc, Where section names are arbitrary phrases and section contents will contain free text except section name. I need to split this text into object pairs of type (s...

AS3 Regular expression

Hi, Any of you gone through this task? Please tell me a solution. I have to extract video id alone from youtube url : http://www.youtube.com/watch?v=Ls8ppLu72NQ&amp;feature=popular From this i need only Ls8ppLu72NQ How can i extract it. I know i can use string replace but is there a way to extract it easily with regex. Url can be ...

Write a regex for a pattern?

a + (ab or cd ) + g is my expression. How can I write a regex in Python to match these? ...

Javascript to validate password

Hi, I am new to regular expressions.Can anyone help me in writing a regular expression on the following description. The password contains characters from at least three of the following five categories: English uppercase characters (A - Z) English lowercase characters (a - z) Base 10 digits (0 - 9) Non-alphanumeric (For example: !, $,...

Java RegEx meta character (.) and ordinary dot ?

Hi, In Java RegEx, how to find out the difference between .(dot) the meta character and the normal dot as we using in any sentence. How to handle this kind of situation for other meta characters too like (*,+,/d,...) ...

Regex for a simplified HQL syntax

Hi all, I intended to provide my view/business layer with the possibility to send HQL queries in strings to my data layer. However, the data layer needs to analyze and manipulate these queries (in particular, add a criterion in the where clause). The supported forms of HQL queries are any combination of the following: from ... where ...

regex error - nothing to repeat

hey guys, When i use this expression: re.sub("([^\s\w])(\s*\1)+","\\1","...") I checked the regex at gskinner, its supposed to return me '.' but it doesn't work. If i use re.sub(r"([^\s\w])(\s*\1)+","\\1","...") It returns me the error: raise error, v # invalid expression sre_constants.error: nothing to repeat Can...