regex

What would be the RegularExpression for the followings?

I have a nomenclature to respect while performing some tasks against the Active Directory. Here's the nomenclature: TT-EEE-Mnemonic: if TT = 'GA' or 'GS' or 'PA' or 'PF' -> the schema to create is a "group", with a groupScope of Global. LT-EEE-Mnemonic: if T = 'A' or 'G' or 'I' or 'N' or 'P' -> the schema to create is a "gro...

Efficiency of Preg_replace

Executive Summary: preg_replace() ran faster than string comparisons. Why? Shouldn't regular expressions be slower? In a recent question about detecting any of an array of disallowed substrings within a given input, I suggested comparing the result of a preg_replace() call to the original input, since preg_replace() can take an array...

search and replace text inline in file in Python

I am trying to convert a file which contains ip address in the traditional format to a file which contains ip address in the binary format. the file contents are as follows. src-ip{ 192.168.64.54 } dst-ip{ 192.168.43.87 } The code i have is as follows. import re from decimal import * filter = open("filter.txt", "r") output = open...

Counting items of a rendered menu - PHP/Regex/XPath

Hi there! :D Guys, I need some help! I have a fully rendered menu (a safe html output)... and I need the number of <li> ONLY of its first level... example: <li><a>first</a></li> <li><a>first</a></li> <li> <a>first</a> <ul> <li><a>second</a></li> <li> <a>second</a> <ul> <li><a>third</a></li> </ul> ...

Python regex, how-to group an item within a regex

Hi all, I'm having trouble creating a regex. Here is a sample of the text on which the regex should work: <b>Additional Equipment Items</b> <br> 40001 <br> 1 Battery Marathon L (8 cells type L6V110) <br> 40002 <br> What I now want to select is >>1<< and >>Battery Marathon L (8 cells type L6V110)<<. Therefore I have produced the...

Regexp pattern Optional character

I want to match a string like 19740103-0379 or 197401030379, i.e the dash is optional. How do I accomplish this with regexp? ...

php preg_replace url

Hi, I have a string: By Chris Sheridan MADRID, Spain -- Rudy Fernandez is not returning calls from Portland Trail Blazers coach Nate McMillan and was fined $25000 by the NBA on ... var make_url = 'http://goog.com/Escape_Space_Link'; My question is how do I use regex and php's preg_replace to remove the entire var make_ur...

PL/SQL Oracle regular expression doesn't work for occurencce of zero

Hi everyone, I have a problem in matching regular expression in Oracle PL/SQL. To be more specific, the problem is that regex doesn't want to match any zero occurrence. For example, I have something like: select * from dual where regexp_like('', '[[:alpha:]]*'); and this doesn't work. But if I put space in this statement: select * ...

Should regular expressions handle case or should we specify the case to match in code?

Following on from this question I asked yesterday: http://stackoverflow.com/questions/3519549/can-i-shorten-this-regular-expression The solution was to use the following expression: ^([a-z]{5}-){4}[a-z]{5}$ To check for a match for a string with the following format: aBcDe-fghIj-KLmno-pQRsT-uVWxy I was advised to omit the A-Z fro...

Unix grep regex how to grep for

Hi I have a text file $ cat test.log SYB-01001 SYB-18913 SYB-02445 SYB-21356 I want to grep for 01001 and 18913 only whats the way to do this I want the output to be SYB-01001 SYB-18913 SYB-02445 I tried this but not sure whats wrong with it grep 'SYB-(18913)|0*)' test.log ...

Remove trailing newline

I've a MySQL database from which I extract a string which is a list of words separated by newline. Now I want to remove only the trailing newline. I tried using preg_replace as $string = preg_replace('/\n/','',$string); It works but all the newlines in the strings are removed :( Please help Thanks everyone. ...

Linebreak in WinForms Textbox

I'm having some trouble dealing with linebreaks here. Basically, the user puts in some data to a textbox that is then saved directly to the database. When I display the data in my program, I only want to display the first line of the textbox, so I tried Regex newLine = new Regex("/[\r\n]+/"); String[] lines = newLine.Split(row[data.tex...

How to find a line containing a string of a particular pattern using regex?

I have a script file containing 1000 lines of data and some of the lines contain some date string in the form of dd/mm/yyyy hh:mm:ss format. My objective is to find out the lines which contain a date of the following pattern "Value=10/08/2010 13:39:37", ENDITEM, Some example lines which contains dates in the script are "Name=s_1_1_8...

Highlight key words in a given search text

Hi, I'm using following method to highlight the keywords in a given text. private string HighlightSearchKeyWords(string searchKeyWord, string text) { Regex keywordExp = new Regex(@" ?, ?"); var pattern = @"\b(" + keywordExp.Replace(Regex.Escape(searchKeyWord), @"|") + @")\b"; Regex exp = new R...

jquery 'regex' toggle

I have an id of the form id = MAIN. When a button is clicked, I want ALL other id's in the dom of the form (MAIN_*) where * is any string to be toggled, so: $(something).toggle(); // will toggle all id's MAIN_* How would I do this in the click event of my button? ...

Help with Regex using preg_match

Hi, Recently i've switched to PHP 5.3+ and after that migration i learned that the eregi() function has been depreciated, its the function i mostly used for my regex needs. But now i had to switch to preg_match() function, i am having trouble validating a certain condition. Hello World I want the preg_match to validate the above "hel...

Regular expression for Character only a-z, A-Z

I dont know how to create regular expression in javascript or Jquery I want to create a regular expression that will check if string contains only characters between a-z and A-Z with any arrangement EDIT When I tried to make regex /^[a-zA-Z\s]+$/ to accept white spaces as well. It is not working. What could be the mistake. I am t...

Regular Expression that is Eval'ed with Word Boundaries

I'm trying to create a bad word filter that throws out tweets that contain any of the words in a provided list, case insensitive. Only problem is that I want to do a simple encoding of the bad word list so that bad words are not downloaded to the client browser. I think the only way I can do it is by eval'ing a regular expression. Only t...

Perl, counting words with special characters

I need to count number of words including special characters like % ,$ in a particular section of an XML document. I need to write this in Perl script using regular expressions. Anyone has any suggestions on where I can start to look for more info as this is my first perl script. I need help with isolating the section and its data. ...

Extract string from string using RegEx in the Terminal

I have a string like first url, second url, third url and would like to extract only the url after the word second in the OS X Terminal (only the first occurrence). How can I do it? In my favorite editor I used the regex /second (url)/ and used $1 to extract it, I just don't know how to do it in the Terminal. Keep in mind that url is a...