regex

BBcode regex

I'm terrible with regex, but I've had a try and a Google (and even looked in reddit's source) and I'm still stuck so here goes: My aim is to match the following 'codes' and replace them with the HTML tags. It's just the regex I'm stuck with. **bold text** _italic text_ ~hyperlink~ Here's my attempts at the bold one: ^\*\*([.^\*]+)\*...

what's the best way to parse a body of text against multiple (15+) regexes on each line?

I have a body of text that I have to scan and each line contains at least 2 and sometimes four parts of information. The problem is that each line can be 1 out of 15-20 different actions. in ruby the current code looks somewhat like this: text.split("\n").each do |line| #around 20 times.. .............. expressions['actions']...

How do I use regular expressions in bash scripts?

I want to check if a variable has a valid year using a regular expression. Reading the bash manual I understand I could use the operator =~ Looking at the example below, I would expect to see "not OK" but I see "OK". What am I doing wrong? i="test" if [ $i=~"200[78]" ] then echo "OK" else echo "not OK" fi ...

Locate Pattern the Letter I followed by a space then three alpha numerics followed by a space

Need to locate the following pattern: The letter I followed by a space then three alpha numerics followed by a space "I ALN " "I H21 " "I 31M " these items are also followed by a lat/lon that is trapped by this expression: Dim regex As New Regex("\d{6} \d{7}") Can the expressions be combined to return a match that would look like: ...

Is Dot in RegEx Dangerous

I'm under the impression that the Dot '.' (wild card) character is dangerous to use. Is my fear unfounded? Thanks ...

Search for a regexp in a java arraylist

ArrayList <String> list = new ArrayList(); list.add("behold"); list.add("bend"); list.add("bet"); list.add("bear"); list.add("beat"); list.add("become"); list.add("begin"); There is a way to search for the regexp bea.* and get the indexes like in ArrayList.indexOf ? EDIT: returning the items is fine but I need something with more per...

Lightweight regex parser

I'd like to use a Regex parser to aid in some string processing in a C application. I'm ideally looking for something lightweight and open-source. The target platform is an embedded system so we're looking to save as much as possible with memory consumption in particular. I've found a number of options online but was wondering if anyone ...

How do I filter all HTML tags except a certain whitelist?

This is for .NET. IgnoreCase is set and MultiLine is NOT set. Usually I'm decent at regex, maybe I'm running low on caffeine... Users are allowed to enter HTML-encoded entities (<lt;, <amp;, etc.), and to use the following HTML tags: u, i, b, h3, h4, br, a, img Self-closing <br/> and <img/> are allowed, with or without the extra spa...

I need a regEx to match general URLs.

I need to test for general URLs using any protocol (http, https, shttp, ftp, svn, mysql and things I don't know about). My first pass is this: \w+://(\w+\.)+[\w+](/[\w]+)(\?[-A-Z0-9+&@#/%=~_|!:,.;]*)? (PCRE and .NET so nothing to fancy) ...

How do I replace 'php3' with 'php' inside every file in a directory.

Hopefully a nice simple one. I've got a php3 website that I want to run on php 5.2 To start with I'd just like to have every reference to the current "index.php3" _within_each_file_ (recursively) changed to "index.php" and then move on to worrying about globals etc. K. Go! :) Update: Thanks a lot! I realise that my question missed ...

Regex for parsing SQL parameters

If I have a query such as SELECT * from authors where name = @name_param, is there a regex to parse out the parameter names (specifically the "name_param")? Thanks ...

Simple regular expression for decimal numbers?

I know this may be the simplest question ever asked on Stack Overflow, but what is the regular expression for a decimal with a precision of 2? Valid examples: 123.12 2 56754 92929292929292.12 0.21 3.1 Invalid examples: 12.1232 2.23332 e666.76 Sorry for the lame question, but for the life of me I haven't been able to find anyone th...

Help Modifying RegEx To Return Range of Digits

Currently this expression "I ([a-zA-z]\d]{3} " returns when the following pattern is true: I AAA I Z99 I need to modify this so it will return a range of alphanumerics after the I from 2 to 13 that do not have a space. Example: I AAA I A321 I ASHG310310 Thanks, Dave ...

Help creating RegEx to Find this pattern

Need to an expression that returns only things with an "I" followed by either a "J" or a "V" (No Quotes) and then a minimum of 1 number up to 3 numbers. I J### I V### I J## I V## I J# I v# Thank to everyone who has already helped! ...

ignoring folders in mercurial

Caveat: I try all the posibilities listed here: http://stackoverflow.com/questions/254002/how-can-i-ignore-everything-under-a-folder-in-mercurial. None works as I hope. I want to ignore every thing under the folder test. But not ignore srcProject\test\TestManager I try syntax: glob test/** And it ignores test and srcProject\test...

How can I translate the following filename to a regular expression in Python?

I am battling regular expressions now as I type. I would like to determine a pattern for the following example file: b410cv11_test.ext. I want to be able to do a search for files that match the pattern of the example file aforementioned. Where do I start (so lost and confused) and what is the best way of arriving at a solution that bes...

Why does Regex.Match return only 1 result?

I'm using a regex that strips the href tags out of an html doc saved to a string. The following code is how I'm using it in my C# console app. Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']"); if (m.Success) { ...

regex (in PHP) to match & that aren't HTML entities

Here's the goal: to replace all standalone ampersands with &amp; but NOT replace those that are already part of an HTML entity such as &nbsp;. I think I need a regular expression for PHP (preferably for preg_ functions) that will match only standalone ampersands. I just don't know how to do that with preg_replace. ...

Java Regular Expressions Replacement

Just could not get this one and googling did not help much either.. First something that I know: Given a string and a regex, how to replace all the occurrences of strings that matches this regular expression by a replacement string ? Use the replaceAll() method in the String class. Now something that I am unable to do. The regex I hav...

Parsing GPS receiver output via regex in Python

I have a friend who is finishing up his masters degree in aerospace engineering. For his final project, he is on a small team tasked with writing a program for tracking weather balloons, rockets and satellites. The program receives input from a GPS device, does calculations with the data, and uses the results of those calculations to con...