regex

Django, custom template filters - regex problems

I'm trying to implement a WikiLink template filter in Django that queries the database model to give different responses depending on Page existence, identical to Wikipedia's red links. The filter does not raise an Error but instead doesn't do anything to the input. WikiLink is defined as: [[ThisIsAWikiLink | This is the alt text]] Her...

Perl regex not breaking out of until loop as expected.

When I print the result of the regex I am attempting to use to control the until loop it gives me the 1 or null I am expecting. Why is it that the code below won't work but if I uncomment the fifth line it works fine? print("Please enter 1, 2, 3 or 4 : "); my $channelSelection = ""; until ($channelSelection =~ /^[1-4]$/) { chomp(m...

PHP Regex Difficulty

I am having difficulty doing regular expressions when there is whitespace and carriage returns in between the text. For example in this case below, how can I get the regular expression to get "<div id="contentleft">"? <div id="content"> <div id="contentleft"> <SCRIPT language=JavaScript> I tried id="content">(.*?)<SCRIPT but...

Regular Expressions Matching on multiple seperated charecters

In this string: "<0> <<1>> <2>> <3> <4>" I want to match all instances of "<\d{1,2}>" except those i have escaped with an extra set of triangle brackets, eg i want to match 0,2,3,4 but not 1, eg: "<0> <<1>> <2>> <3> <4>" I want to do this in one single regular expression but the best i could get is: (^|[^\<])\<(?<1>\d{1,2})>([^>...

python, regular expressions, named groups and "logical or" operator

Hello. In python regular expression, named and unnamed groups are both defined with '(' and ')'. This leads to a weird behavior. Regexp "(?P<a>1)=(?P<b>2)" used with text "1=2" will find named group "a" with value "1" and named group "b" with value "2". But if i want to use "logical or" operator and concatenate multiple rules, the fo...

Regular epressions in Linux/HPUX

Is there a difference in regular expressions on Linux and on HPUX? I am using them in sed. I am trying the following which works only on Linux: sed -e "s/^\s*ant\s*$/#ant/g" Makefile Now I see that if I remove the '^' then it works on HP too. As far as I understand, this should be supported by both. ...

Regex for lex

I am developing a simple translator from MathML to Latex, using Lex and Yacc. In my lex file containing the regex rules I have one defined for arithmetic operators [-+*=/]. I want to extended so that it would recognize plus-minus (+-) and invisible times ('&InvisibleTimes'), but I'm unfamiliar with regex and I need some help. ...

sed beginner: changing all occurrences in a folder

I need to do a regex find and replace on all the files in a folder (and its subfolders). What would be the linux shell command to do that? For example, I want to run this over all the files and overwrite the old file with the new, replaced text. sed 's/old text/new text/g' ...

How to find text within [] in Sed?

This is similar to a question that has already been asked. However, I am looking for a Sed specific answer. I have text similar to the following: Some sample text [with some extra text].foo I need to grab just the text inside the brackets. My attempts thus far have been futile. I can parse the line with other tools but I can't seem...

How do I determine an image url string is without a base domain through javascript?

I'm capturing data from an external url using php and throwing it back to my page via ajax to load images. My problem is the external url have some images that are relative("images/example.jpg") so I have to prepend their base domain("http://www.example.com) so I can load it in my page. Problem is some of the images includes a base domai...

Regular Expression's Meta Character

Language: asp This is sample of my code: str = "www.url.com/gotobuy.aspx?id=1234" key_word = ".obuy." Dim regEx Set regEx = New RegExp regEx.Pattern = key_word regEx.IgnoreCase = True regEx.Global = True Set Matches = regEx.Execute(str) if matches.count > 0 then new_string = str For Each Match in Matches new_string = replace(new_s...

Regular Expression

Hi, What will be the regular expression to accept 'CP123' First two letters CP and other 3 or 4 or 5 nos. ...

regex does not remove non digits from string

I have the following string "item number:237728" I'm applying replace str.replace(/[^0-9]/g,''); but the string does not change, non digits are not removed. any idea why? thanks ...

Regex: Named Capturing Groups in .NET

I'm having a hard time finding a good resource that explains how to use Named Capturing Groups in C#. This is the code that I have so far: string page = Encoding.ASCII.GetString(bytePage); Regex qariRegex = new Regex("<td><a href=\"(?<link>.*?)\">(?<name>.*?)</a></td>"); MatchCollection mc = qariRegex.Matches(page); CaptureCollection c...

How to filter using Regx and javascript?

I have some text in an element in my page, and i want to scrap the price on that page without any text beside. I found the page contain price like that: <span class="discount">now $39.99</span> How to filter this and just get "$39.99" just using JavaScript and regular expressions. The question may be too easy or asked by another way...

Parsing HTML document: Regular expression or LINQ?

Trying to parse an HTML document and extract some elements (any links to text files). The current strategy is to load an HTML document into a string. Then find all instances of links to text files. It could be any file type, but for this question, it's a text file. The end goal is to have an IEnumerable list of string objects. That par...

Regex Search Help

Given a string such as: a:2:{i:0;s:1:"1";i:1;s:1:"2";} I want to find every integer within quotes and create an array of all integers found in the string. End result should be an array like: Array ( [0] => 1 [1] => 2 ) I'm guessing you use preg_match() but I have no experience with regular expressions :( ...

Java regular expression to identify strings with more digits than non-digits

How can I identify strings containing more digits than non-digits using regular expression (Pattern) in Java? Thank you. ...

Simple regex required

I've never used regexes in my life and by jove it looks like a deep pool to dive into. Anyway, I need a regex for this pattern (AN is alphanumeric (a-z or 0-9), N is numeric (0-9) and A is alphabetic (a-z)): AN,AN,AN,AN,AN,N,N,N,N,N,N,AN,AN,AN,A,A That's five AN's, followed by six N's, followed by three AN's, followed finally by two A...

Regex Subtitution in Python

I have a CSV file with several entries, and each entry has 2 unix timestamp formatted dates. I have a method called convert(), which takes in the timestamp and converts it to YYYYMMDD. Now, since I have 2 timestamps in each line, how would I replace each one with the new value? EDIT: Just to clarify, I would like to convert each occur...