regex

Rexexp. Big text with hierarchy

I have a text of law, with Chapters and Articles. Chapter 1. Something Article 1. trata-trata Article 2. trata-trata Article 3. trata-trata Chapter 2. Something Article 4. trata-trata Article 5. trata-trata Article 6. trata-trata I need regexp, to find Articles within Chapters, and know what articles belongs to what Chapter. (...

How can I find strings that have mixed cased with Perl?

I'm trying to filter thousands of files, looking for those which contain string constants with mixed case. Such strings can be embedded in whitespace, but may not contain whitespace themselves. So the following (containing UC chars) are matches: " AString " // leading and trailing spaces together allowed "AString " // trailing sp...

Validate an email address is valid and came from a specific Domain

Given an email address, say: [email protected] In Coldfusion, how can i validate that the email is from "google.com" and not another domain? ...

How to match the word exactly with regex?

Hi, I might be asking this question incorrectly but what I would like to do is the following: Given a large String which could be many 100s of lines long match and replace a word exactly and make sure it does not replace and match any part of any other String. For example : Strings to Find = Mac Apple Microsoft Matt Damon I.B.M. Hur...

Find two of the same character in a string with regular expressions

This is in reference to a question I asked before here I received a solution to the problem in that question but ended up needing to go with regex for this particular part. I need a regular expression to search and replace a string for instances of two vowels in a row that are the same, so the "oo" in "took", or the "ee" in "bees" and ...

Regex for splitting

I'd like to split a string such as "[1-5]?3456[2-5][4-D]" to array[0] = "[1-5]" array[1] = "?" array[2] = "3" array[3] = "4" array[4] = "5" array[5] = "6" array[6] = "[2-5]" array[7] = "[4-D]" Can anybody tell me if that's possible with a regex that splits? I got three elements "3" a letter (which can be 1-9 and A-F, "?" a whiteca...

Need a RegEx guru..

I'm trying to write a script that parses a block of HTML and matches words against a given glossary of terms. If it finds a match, it wraps the term in <a class="tooltip"></a> and provides a definition. It's working okay -- except for two major shortcomings: It matches text that is in attributes It matches text that is already in an <...

C# Regex: How Can I Replace Tokens With Strings Generated at Run-time?

Given the following input and regex strings: const string inputString = "${Principal}*${Rate}*${Years}"; const string tokenMatchRegexString = @"\${([^}]+)}"; How can I replace each token (i.e. ${Principal}, ${Rate}, and ${Years}) with the return value of my 'ReplaceToken' function? private static string ReplaceToken(string tokenStrin...

Strip trailing characters from path string

I am new to regex and am looking to trim a known number of characters off the end of a string. The string represents a filepath, so instead of c:\test\test1\test2, I would like to strip off the trailing characters leaving c:\test. The trouble that I am having is with the backslashes. What sort of regex would I use to do this? ...

ruby regular expression and extraction from string

I've the following string. How can I extract out the "somesite.com/2009/10/monit-on-ubuntu/" part from it using ruby regular expression? http://linkto.com/to/1pyTZl/somesite.com/2009/10/monit-on-ubuntu/t The common is, starts with "/to/some-alpha-num" and always ends with "/t" ...

How do I match non-ASCII characters with RegexKitLite?

I am using RegexKitLite and I'm trying to match a pattern. The following regex patterns do not capture my word that includes N with a titlde: ñ. Is there a string conversion I am missing? subjectString = @"define_añadir"; //regexString = @"^define_(.*)"; //this pattern does not match, so I assume to add the ñ //regexString = @"^def...

python regular expression across multiple lines

I'm gathering some info from some cisco devices using python and pexpect, and had a lot of success with REs to extract pesky little items. I'm afraid i've hit the wall on this. Some switches stack together, I have identified this in the script and used a separate routine to parse the data. If the switch is stacked you see the following (...

Masking a string in perl using a mask string

I have a string such as 'xxox-x' that I want to mask each line in a file against as such: x's are ignored (or just set to a known value) o's remain unchanged the - is a variable length field that will keep everything else unchanged therefore mask 'xxox-x' against 'deadbeef' would yield 'xxaxbeex' the same mask 'xxox-x' against 'dea...

How to use re to search for items in one list inside another list in Python

I am reading a list of strings, each of which relate to a file name. However, each string is minus the extension. I have come up with the following code: import re item_list = ['item1', 'item2'] search_list = ['item1.exe', 'item2.pdf'] matches = [] for item in item_list: # Match item in search_list using re - I assume this is the be...

regular expression matching dates

Need to match date in a user submitted string it should work with these different formats jan 1 2000 january 1 2000 jan. 1 2000 1/1/2000 2000 january how would you write this regular expression? ...

Regex To Validate Model/Part Numbers

Hi, I'm trying to write a regex to validate part or model numbers. These can contain letters, numbers, '-', '/' and spaces. They must contain at least 1 number and be between 4 and 20 characters long. Here are some examples of the strings I want to match: CVA 620 999 M3094 26250 APL8215/APL8225 1301 02-700401 This is what I have s...

PHP regex for filtering out urls from specific domains for use in a vBulletin plug-in

I'm trying to put together a plug-in for vBulletin to filter out links to filesharing sites. But, as I'm sure you often hear, I'm a newb to php let alone regexes. Basically, I'm trying to put together a regex and use a preg_replace to find any urls that are from these domains and replace the entire link with a message that they aren'...

RegEx for an invoice format

I'm quite new to regular expressions and I'm trying to create a regex for the validation of an invoice format. The pattern should be: JjYy (all 4 characters are legit), used 0, 2 or 4 times e.g. no Y's at all is valid, YY is valid, YYYY is valid, but YYY should fail. Followed by a series of 0's repeating 3 to 10 times. The whole should ...

Search and replace in VS2008 - linebreak

If I need to replace a text <p> this text including the paragraph needs to be replaced </p> How can I do this with VS2008 "search and replace"? EDIT One way is to use regex like suggested by Daniel. Its just pretty complicated. The real searchexpression at the end was: \<div id="searchStore"\>\n[^\<]*\<[^\>]*\>\n[^\<]*\<[^\>]*\> ...

Regular expression for not matching two underscores.

I don't know whether it's really easy and I'm out of my mind.... In Ruby's regular expressions, how to match strings which do not contain two consecutive underscores, i.e., "__". Ex: Matches: "abcd", "ab_cd", "a_b_cd", "%*##_@+" Does not match: "ab__cd", "a_b__cd" -thanks EDIT: I can't use reverse logic, i.e., checking for "__" str...