regex

JavaScript: add or subtract from number in string

I have a string that looks like "(3) New stuff" where 3 can be any number. I would like to add or subtract to this number. I figured out the following way: var thenumber = string.match((/\d+/)); thenumber++; string = string.replace(/\(\d+\)/ ,'('+ thenumber +')'); Is there a more elegant way to do it? ...

Extracting a block of text where the closing expression depends on the opening one.

I have a text string structured like this: = Some Heading (1) Some text == Some Sub-Heading (2) Some more text === Some Sub-sub-heading (3) Some details here = Some other Heading (4) I want to extract the content of second heading, including any subsection. I do not know beforehand what is the depth of the second heading, so I n...

regex or something to find a file in php

I have a name in a database, lets say its "DFectuoso" and some legacy system stored DFectuoso_randomnameofafile.doc. Now I want to find all the filed "DFectuoso" owns and display links to them in a PHP page. What would be the way to start on this? ...

Extract email addresses from a block of text

How can I create an array of email addresses contained within a block of text? I've tried addrs = text.scan(/ .+?@.+? /).map{|e| e[1...-1]} but (not surprisingly) it doesn't work reliably. ...

How do I remove all hyphens with a Perl regex?

I thought this would have done it... $rowfetch = $DBS->{Row}->GetCharValue("meetdays"); $rowfetch = /[-]/gi; printline($rowfetch); But it seems that I'm missing a small yet critical piece of the regex syntax. $rowfetch is always something along the lines of: ------S -M-W--- --T-TF- etc... to represent the days of the week a meetin...

Interactive search/replace regex in vim?

I know regex for doing a global replace, %s/old/new/g how do you go about doing an interactive search replace in vim ...

Using Condition in Regular Expressions

eg: Text: <!-- Nav bar --> <TD> <A HREF="/home"><IMG SRC="/images/home.gif"></A> <IMG SRC="/images/spacer.gif"> <A HREF="/search"><IMG SRC="/images/search.gif"></A> <IMG SRC="/images/spacer.gif"> <A HREF="/help"><IMG SRC="/images/help.gif"></A> </TD> Regex: (<[Aa]\s+[^>]+>\s*)?<[Ii][Mm][Gg]\s+[^>]+>(?(1)\s*</[Aa]>) Resul...

Question about "*" in regular expression

Java: String result = "B123".replaceAll("B*","e"); System.out.println(result); The output is: ee1e2e3e Why? ...

Need help with Regular Expression

What is a regular expression for initSock|north|router\r\n Where there is north changes all the time but the rest is always the same. So It can be: initSock|foo|router\r\n initSock|bar|router\r\n etc. But where north, foo or bar are there definitely should be something and can't be empty. I am going to use this in C#. To make it...

How can I remove all characters from string starting at first non-alpha character?

This would have been a lot easier if not for certain situations. Sample data: KENP989SD KENP913E KENPX189R KENP913 What regular expression can I use to remove all characters from the string starting at the first non-alpha character? Basically, I want to find the first non-alpha character and chop everything off after that regardless ...

regex for email validation

I have written the regex below for a really simple email validation. I plan to send a confirmation link. /.*@[a-z0-9.-]*/i I would, however, like to enhance it from the current state because a string like this does not yield the desired result: test ,[email protected], test The "test ," portion is undesirably includ...

How can I find a specific line in a file without using regular expressions in Perl?

I have a file that I want to read in using the File::Slurp module then search that file for a specific line. I know Perl has regular expressions but the strings I’m searching for are user-generated so don’t want to have to worry about escaping everything. I could write a foreach loop to do this but was wondering if there’s a function in ...

How do I separate a variable from the rest of my Perl regex?

I have a regex where the variable $m_strFirstName is next to other identifier characters that aren't part of the variable name: if($strWholeName =~ m/$m_strFirstName_(+)/) .... I'm trying to extract something like: strWholeName is 'bob_jones' or 'bob_smith' m_strFirstName is 'bob' and I want the 'smith' or 'jones' part of the strin...

Regular expression to find a line containing certain characters and remove that line

Hi, I have text file which has lot of character entries one line after another. I want to find all lines which start with :: and delete all those lines. What is the regular expression to do this? -AD ...

javascript function which ensures a text contains only dollar symbols formatted as $placeholder$

I need a javascript function which gets a string and returns false if the string contains - Any unclosed dollar symbol - Or a closed dollar symbol with something between dollars different than a series of characters function validateFormat(text) { // Do stuff } For example if text: validateFormat("blab abalaba $something$ avava $aff...

Regex in Java, finding start and end tag

I am trying to find data within a HTML document. I don't need a full blown parser as it is just the data between one tag. But, I want to detect the 'select' tag and the data in between. return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL); /// E...

Javascript Regex object and the dollar symbol

In the code below. I expected true but i am getting false instead. What am I missing? var text = "Sentence $confirmationlink$ fooo"; alert(placeHolderExists(text,'confirmationlink'); // alerts false function placeHolderExists(text,placeholdername) { var pattern = new RegExp('\$'+placeholdername+'\$'); return pattern.te...

Javascript search and replace

I would like do do the following in Javascript (pseudo code): myString.replace(/mypattern/g, f(currentMatch)); that is, replace string isn't fixed, but function of current match. ...

T-SQL check constraint for .NET TimeSpan?

I have a nvarchar(max) column in a sql server 2005 table which is used for storing string representations of .NET TimeSpan objects. Sometimes the table is manually edited. I want to add a check constraint to verify that the string can be parsed by TimeSpan.Parse(). How should I do this? I guess I could use one of the methods for enabling...

How does RegexOptions.Compiled work?

What is going on behind the scenes when you mark a regular expression as one to be compiled? How does this compare/is different from a cached regular expression? Using this information, how do you determine when the cost of computation is negligible compared to the performance increase? ...