regex

What is wrong with my regex (simple)?

I am trying to make a regex that matches all occurrences of words that are at the start of a line and begin with #. For example in: #region #like #hey It would match #region and #hey. This is what I have right now: ^#\w* I apologize for posting this question. I'm sure it has a very simple answer, but I have been unable to find it...

Need to extract special tags and replace them based upon their contents using regular expression

Hi everyone, I'm working on a simple templating system. Basically I'm setting it up such that a user would enter text populated with special tags of the form: <== variableName ==> When the system would display the text it would search for all tags of the form mentioned and replace the variableName with its corresponding value from a da...

Is this regular expression exponential?

Hi, I would like to know if: /.*(Set-Cookie: (.*))?;.*(<\?xml.*)/ is an exponential regexp. Thanks ...

Find and kill a process in one line using bash and regex.

I often need to kill a process during programming. The way I do it now is: [~]$ ps aux | grep 'python csp_build.py' user 5124 1.0 0.3 214588 13852 pts/4 Sl+ 11:19 0:00 python csp_build.py user 5373 0.0 0.0 8096 960 pts/6 S+ 11:20 0:00 grep python csp_build.py [~]$ kill 5124 How can I extract the process id ...

PHP single quotes regex

This topic is a remark for http://stackoverflow.com/questions/3510535/php-get-image-src So we have a variable with code inside (only image): $image = "<img src='http://www.gravatar.com/avatar/66ce1f26a725b2e063d128457c20eda1?s=32&amp;d=identicon&amp;r=PG' height='32' width='32' alt=''/>"; How can we get src of this image? We should t...

Date from ajaxcontroltoolkit calendarextender

I have the date in format od MM/yyyy. I need to validate that this MM/YYYY is greater than or equal to present month and year.Any built in support function present or do I have to write a custom function to validate.If so how can this be done? ...

regex to identify anchor tag which should not be nested

From the html source I've to identify anchor tag which shouldn't be nested. For example: <a href="http://www.abc.com"&gt;abc&lt;a href="http://www.dbc.com"&gt;dbc&lt;/a&gt; From this on first match it should return <a href="http://www.abc.com"&gt;abc On subsequent find <a href="http://www.dbc.com&gt;dbc&lt;/a&gt; While findin...

How to search a line starting with a certain text using regex

/** Constant <code>IDX_USER="IDX_+ USER_ID"</code> */ I have several lines of code which was generated by javadoc and show up something like the above. I would want to find all lines starting with /** Constant IDX_ and all the way to the end of the line. How should I do this? Will be using the regex search and replace capability in Ec...

Number replace pattern issue with RegEx

I have the string page-24 and want to replace 24 by any other number. The script is written in PHP and uses preg_replace, however this problem should be independent from the programming language. My match pattern is: (.*-)(\d*) The replace pattern would be: $1[insert number here]$2 The backreferences work, but I cannot insert a numbe...

Non capturing group?

After reading some tutorials I still don't get it. Could someone explain how ?: is used and what it's good for? ...

Using VB.NET Regular Expressions to Remove Excel XML Conversion

I have the following lines showing up in files that have been converted to XML from an Excel worksheet: <Worksheet ss:Name="Sheet1"> <Names> <NamedRange ss:Name="Print_Area" ss:RefersTo="=Sheet1!R30C1:R8642C15"/> </Names> <Table ss:ExpandedColumnCount="14" ss:ExpandedRowCount="8655" x:FullColumns="1" x:FullRows="1" ss:Style...

replace all smileys by enumeration in php

Is there any fast (regex-based?) method to replace all smileys in a text, each by an unique corresponding identifier? For example, the first occurrence of :) should be replaced by smiley1, the :)) by smiley2 and another occurrence of :) by smiley1 again? Furthermore, the identifyier should be the same using different text for input Any ...

Regex match HTML tag NOT containing another tag.

I am writing a regex find/replace that will insert a <span> into every <a href> in a file where a <span> does not already exist. It will allow other tags to be in the <a href> like <img>, <b>, etc. Currently I have this regex: Find: (<a[^>]+?style=".*?color:#(\w{6}).*?".*?>)(.+?)(<\/a>) Replace: '$1<span style="color:#$2;">$3</span>$4' ...

How do I parse only foreign characters from the text in an HTML file with regular expressions

I'm trying to parse HTML and automatically change the font of any foreign characters, and I'm having some issues. There are a few different hackish ways I'm trying to accomplish this, but none work really well, and I'm wondering if anyone has any ideas. Is there any easy way with python to match all the foreign characters (specifically, ...

Search block of text, return MP3 links using PHP

Hi guys, I've just run into a little bit of trouble with some PHP on my latest project. Basically I have a block of text ($text) and I would like to search through that text and return all of the MP3 links. I know it has something to do with regular expressions but I just cannot get it working. Here's my current code: if(preg_match...

A regular expression to filter undesired usernames

On a site I am working on I have a requirement that usernames not start with <alpha><alpha>_ So these should not be allowed: SU_Coolguy MR_Nobody my_Pony But these should be ok: __SU_Coolguy MRS_Nobody YourPony In the framework I am using, I am only able to validate against matching regular expression, not non-matchi...

Strategy/Example for Parsing Loosely Formatted Addresses?

We have a field in our application that needs to support US city/zip inputs along the following lines: Boston, MA MA 02114 Zone 0 That last input, "Zone 0" is specific to our industry, but can be anything matching "Zone #". There are of course, variations about these themes: Boston MA 02114 grand rapids mi ai oh I'm curious if an...

ruby regex find and replace

I have the following output: time = 15:40:32.81 and I want to eliminate : and the . so that it looks like this: 15403281 I tried doing a time.gsub(/\:\s/'') but that didn't work. Thanks for your help in advance ...

How do I use a ruby regex to get a substring?

I want to get the numbers out of strings such as: person_3 person_34 person_356 city_4 city_15 etc... It seems to me that the following should work: string[/[0-9]*/] but this always spits out an empty string. ...

check text area for certain character combinations

I have a text area which gets filled in various ways including paste, keyboard input, from an autocomplete etc. Now I want to validate this text area and if contains any combination, including multiples of some characters and if so, set it to empty. The characters I want to filter are: tabs, new lines, spaces, carriage returns, as wel...