regex

Is there a Perl-compatible regular expression to trim whitespace from both sides of a string?

Is there a way to do this in one line? $x =~ s/^\s+//; $x =~ s/\s+$//; In other words, remove all leading and trailing whitespace from a string. ...

Regular expression to match start of filename and filename extension

What is the regex to match filenames that start with 'Run' and have a filename extension of '.py'? It should match any of the following: RunFoo.py RunBar.py Run42.py It should not match: myRunFoo.py RunBar.py1 Run42.txt (I am a regex novice and am more familiar with sql wildcards so the equivalent of what I am searching for would ...

How can I concatenate regex literals in Javascript?

Is it possible to do something like this? var pattern = /some regex segment/ + /* comment here */ /another segment/; Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the literal as the code is both more self-evident and concise. ...

Regex Search & Replace Program

Is there a simple and lightweight program to search over a text file and replace a string with regex? ...

Regular expression that uses an "OR" conditional

I could use some help writing a regular expression. In my Django application, users can hit the following URL: http://www.example.com/A1/B2/C3 I'd like to create a regular expression that allows accepts any of the following as a valid URL: http://www.example.com/A1 http://www.example.com/A1/B2 http://www.example.com/A1/B2/C3 I...

What do these Unicode characters (codepoints) mean in this regex?

I have the following regular expression : I figured out most of the part which is as follows : ValidationExpression="^[\u0020\u0027\u002C\u002D\u0030-\u0039\u0041-\u005A\u005F\u0061-\u007A\u00C0-\u00FF°./]{1,256}$" u0020 : SPACE u0027 : APOSTROPHE u002C : COMMA u002D : HYPHEN / MINUS u0030-\u0039\ : 0-9 u0041-\u005A : A - Z u005F : UN...

Regular Expression for extracting text from an RTF string

I was looking for a way to remove text from and RTF string and I found the following regex: ({\\)(.+?)(})|(\\)(.+?)(\b) However the resulting string has two right angle brackets "}" Before: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Shell Dlg 2;}{\f1\fnil MS Shell Dlg 2;}} {\colortbl ;\red0\green0\blue0;...

Apache - mod_rewrite RewriteRule question

I have a few problems with my mod_rewrite rules. There a three different url pattern I want to handle. http://example.com/%module%/%view%-%args%.html http://example.com/%module%/%view%.html http://example.com/%module% The following mod_rewrite rules don't really work. Also I've the problem that the query (example: user.html?foo=bar) ...

grep: matching on literal "+"

I need to find occurrences of "(+)" in my sql scripts, (i.e., Oracle outer join expressions). Realizing that "+", "(", and ")" are all special regex characters, I tried: grep "\(\+\)" * Now this does return occurrences of "(+)", but other lines as well. (Seemingly anything with open and close parens on the same line.) Recalling that ...

Regex to find lines containing sequence but not containing a different sequence

How do I write a regular expression to find all lines containing 665 and not having .pdf I can't seem to find how to do not in regex. This is for Notepad++ syntax if it matters. Thanks ...

How do I replace an asterisk ('*') using a Perl regular expression?

I have the following string: $_='364*84252'; The question is: how to replace * in the string with something else? I've tried s/\*/$i/, but there is an error: Quantifier follows nothing in regex. On the other hand s/'*'/$i/ doesn't cause any errors, but it also doesn't seem to have any effect at all. ...

What property returns the regular expression used when re.compile was called?

def foo (): x = re.compile('^abc') foo2(x) def foo2(x): # How do I get x to return '^abc'? logging.info('x is ' + x.???) ...

Regex to validate the index of a website vs. a specific page

I'm looking for a regex that will allow me to validate whether or not a string is the reference to a website address, or a specific page in that website. So it would match: http://google.com ftp://google.com http://google.com/ http://lots.of.subdomains.google.com But not: http://google.com/search.whatever ftp://google.com/search....

Is java.util.regexp efficient enough?

I need to do a lot of searches of certain patterns in source files while the user is changing them, so I need to do regexp matching that is efficient in time and memory. The pattern repeats itself so should be compiled once, but I need to be able to retrieve subparts (rather than just confirm a match) I'm considering using java.util.reg...

JQuery selector regular expressions

I am after documentation on using wildcard or regular expressions (not sure on the exact terminology) with the jquery selector. I have looked for this myself but have been unable to find information on the syntax and how to use it. Does anyone know where the documentation for the syntax is? EDIT: The attribute filters allow you to sele...

Getting the pattern back from a compiled re?

Hi all. Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way to extract the pattern string (^\d+$) back from the x? ...

Matching an (easy??) regular expression using C#'s regex...

Ok sorry this might seem like a dumb question but I cannot figure this thing out : I am trying to parse a string and simply want to check whether it only contains the following characters : '0123456789dD+ ' I have tried many things but just can't get to figure out the right regex to use! Regex oReg = new Regex(@"[\d dD+]+"); oReg...

How to do a regex replacement, adding characters in a date string?

For PHP I have a date I want line wrapped. I have $date = '2008-09-28 9:19 pm'; I need the first space replaced with a br to become 2008-09-28<br>9:19 pm If it wasn't for that second space before PM, I would just str_replace() it. ...

Find beginning of sentence in String

I want to display the results of a searchquery in a website with a title and a short description. The short description should be a small part of the page which holds the searchterm. What i want to do is: 1 strip tags in page 2 find first position of seachterm 3 from that position, going back find the beginning (if there is one) of that ...

Using regular expressions how do I find a pattern surrounded by two other patterns without including the surrounding strings?

I want to use regular expressions (Perl compatible) to be able to find a pattern surrounded by two other patterns, but not include the strings matching the surrounding patterns in the match. For example, I want to be able to find occurrences of strings like: Foo Bar Baz But only have the match include the middle part: Bar I ...