regex

A better JavaScript version of addslashes and stripslashes?

I am using these 2 functions: http://javascript.about.com/library/bladdslash.htm But JSLint complains 'Bad Escapement' on this line: str=str.replace(/\\0/g,'\0'); [Edit] I converted to 2 lines, and now the first line is the one that fails JLint: var rep = '\0'; str=str.replace(/\\0/g,rep); So it is the '\0' can you help? ...

Perl : get substring which matches regex error

I am very new to Perl, so please bear with my simple question: Here is the sample output: Most successful agents in the Emarket climate are (in order of success): 1. agent10896761 ($-8008) 2. flightsandroomsonly ($-10102) 3. agent10479475hv ($-10663) Most successful agents in the Emarket climate are (in order of succes...

Javascript RegEx Question

Hello, How to find below comment block(s) with javascript/jquery regex: /* some description here */ It may even look like: /* some description here */ Or /* some description here */ ...

Javascript regex to match a string that ends with some characters but not with a particular combination of those

Let's say using Javascript, I want to match a string that ends with [abcde]* but not with abc. So the regex should match xxxa, xxxbc, xxxabd but not xxxabc. I am utterly confused. Edit: I have to use regex for some reason, i cannot do something if (str.endsWith("abc")) ...

Regex to detect a proper permalink?

These permalinks above are rerouted to my page: page.php?permalink=events/foo page.php?permalink=events/foo/ page.php?permalink=ru/events/foo page.php?permalink=ru/events/foo/ The events is dynamic, it could be specials or packages. My dilemma is basically; I need to detect an empty link in order so I can feed a robots no index meta ...

regex question: independent position of words

hi all, is it possible to define a regex pattern which checks eg. for 3 terms independent to their position in the main string? eg. my string is something like "click here to unsubscribe: http://www.url.com" the pattern should also work with "http:// unsubscribe click" thx ...

Java String.replaceAll regex

I want to replace the first context of web/style/clients.html with the java String.replaceFirst method so I can get: ${pageContext.request.contextPath}/style/clients.html I tried String test = "web/style/clients.html".replaceFirst("^.*?/", "hello/"); And this give me: hello/style/clients.html but when I do Stri...

A regular expression that will allow a string with only one Capital Letter

The string should be 6 - 20 characters in length. And it should contain 1 Capital letter. I can do this in code using C# string st = "SomeString" Regex rg = new Regex("[A-Z]"); MatchCollection mc = rg.Matches(st); Console.WriteLine("Total Capital Letters: " + mc.Count); if (mc.Count > 1) { ...

Regular Expression Help in .NET

I have a simple pattern I am trying to match, any characters captured between parenthesis at the end of an HTML paragraph. I am running into trouble any time there is additional parentheticals in that paragraph: i.e. If the input string is "..... (321)</p>" i want to get the value (321) However, if the paragraph has this text: "......

How can I extract text from between two delimiters on a line in bash?

What is a regex I can write in bash for parsing a line and extracting text that can be found between two | (so that would be ex: 1: |hey| 2: |boy|) and keeping those words in some sort of array? ...

extjs input text maskRe

In Ext JS, the following maskRe doesn't work in that it doesn't put the restriction of max 5 characters on the text field, why? { xtype: 'textfield', fieldLabel: '* Zip Code', allowBlank: false, maskRe: /\d{0,5}/i } ...

javascript regular expression followed by open square bracket

text = text.replace(/\.(?=[a-zA-Z0-9\[])/g, "<span style='background-color: #FF00FF'>.</span>"); I want to use javascript to highlight all full stops that is followed by letters, numbers and [. The above expression works for letters and numbers, but not bracket. Any idea what's wrong? ...

Regular expression to match maximium of five words.

I have a regular expression ^[a-zA-Z+#-.0-9]{1,5}$ which validates that the word contains alpha-numeric characters and few special characters and length should not be more than 5 characters. How do I make this regular expression to accept a maximum of five words matching the above regular expression. ...

Search and replace in *.aspx,*.ascx files when publishing a Webapplication

Hi all I'm attempting to replace a pattern in all my .aspx and .ascx file when I Publish my Webapplication. When I am running the application locally, I don't care about the replace. But as soon as I need to Publish the solution I need a sequence of characters, let's say "ABC", replaced with "DEF" in all my .aspx and .ascx files. How ...

I need a regular expression to substitute pseudo html in .NET

I have texts like this one: this is a text in [lang lang="en" ]english[/lang] or a text in [lang lang="en" ]spanish[/lang] I need to substitute them for: this is a text in <span lang="en">english </span> or a text in <span lang="es">spanish</span> I need a regular expression, not a simple replace. The languages in the lang tag can ...

codingBat repeatEnd using regex

I'm trying to understand regex as much as I can, so I came up with this regex-based solution to codingbat.com repeatEnd: Given a string and an int N, return a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive. public String repeatEnd(Stri...

Culture specific characters to nice URL format

Hi I need some functionality to make the following string in a url-friendly format: "knæ som gør" should be "kna-som-gor" That is, replacing culture specific characters to characters that can be used in urls. Using .Net and C# Please help me :) /Andreas ...

Using C# regex to select text based on custom tags

I have a string in c# containing some data i need to extract based on certain conditions. The string contains many tenders in the following form : <TENDER> some words, don't know how many, may contain numbers and things like slashes (/) or whatever <DESCRIPTION> some more words and possibly other things like numbers or whatever describ...

replace characters which do not match with the ones in a regex

Hi, I have this regex: private static final String SPACE_PATH_REGEX ="[a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+"; I check if my string matches this regex and IF NOT, i want to replace all characters which are not here, with "_". I've tried like: private static final String SPACE_PATH_REGEX_EXCLUDE = "[~a-z|A-Z|0-9|\\/|\\-|\\_|\\+]+"; i...

Trying to learn regex

Hello everyone I'm trying to learn regex from java website and I try to run this JAVA program but each time I get No Console output, what do I do ? here is the url : http://java.sun.com/docs/books/tutorial/essential/regex/test_harness.html I'm trying this inside eclipse UPDATE : Can anybody suggest some other better way to learn re...