regex

Regex for url validation (unterminated parentheticals error)

I have the following expression to validate a URL but it gives me a syntax error on the browser. I am no expert in regex expressions so I am not sure what I am looking for. I would also like it to test for http:// and https:// urls. "url":{ "regex":"/^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$/", "alertText":"URL must start...

Adding attributes to submitted content links

I have a site where people will submit text. I want to add a couple of attributes to links that are added. Anyone know a regular expression (or another good way) to add rel="nofollow" to any link that is in the body of the text that is submitted? ...

Regex search & replacing the expression with something different for each occurrence of the expression

I am using a vendor-supplied API that uses javascript to output HTML that essentially looks like this: <li class="parent_class"> <a href="link1.html"> Parent Name </a> </li> <div class="child_class"> <li> <a href="link2.html"> Child Name 1 </a> </li> <li> <a href="link3.html"> Child Name 2 </a> </li> </div> <li class="parent_clas...

Removing first newline preg_replace

Hi All, I'm writing some PHP to convert BBcode to HTML. I would like to convert this BBcode: [quote] Hello World [/quote] to the following: <blockquote>Hello World</blockquote> The preg_replace function that I'm using to perform this is: preg_replace("/\[quote\](.+?)\[\/quote\]/s", "<blockquote>\\1</blockquote>", $bbCode); Thi...

REGEX: replace a specific character after the appearence of another character in string

i have this string: owl:Class rdf:about="#other important people" i want with help of vim regex to replace the space with _ but only after the word starting with #. I mean i want finally: owl:Class rdf:about="#other_important_people" sorry for my poor grammar ...

How can I generate paging links from the URL when using mod_rewrite changes the URL

First of all I am in DESPERATE need of help here PLEASE I will most likely start a bounty as soon as SO lets me. I have a pretty large site (social network) MANY PAGES, I am currently doing a complete re-write to build it better then I did 2 years ago. 1 thing I have decided to change is the URLs on my site, there were like this http:/...

Remove Quote in Regex Matching

I have the following string: [assembly: AssemblyVersion("1.0.0.0")] The issue now is that I have to extract the 1.0.0.0 out. Here's the regular expression that I can come out with: var pattern = "[^\\/]+\\[[a-z]+:\\s" + "AssemblyVersion"+ "(?:Attribute)?\\((.+)\\)\\]" ; var theString ="[assembly: AssemblyVersion("1.0.0.0")]"; var...

Regular Expression Problem: Match in Context

I have a structured file with hierarchical text which describes a GUI in Delphi (a DFM-File). Let's assume I have this file and I have to match all "Color = xxx" Lines, which are in the context of TmyButton (marked), but not those in other context. Within the TMyButton-Context there won't be a deeper hierarchical level. object frmMain:...

How can I make substitutions only on the parts of the string between < and > in Perl?

For example, $thisMessage contains: <...> <request attribs="true" text="this is a message" ...>text here too</request> </...> The desired output should be, <...> <request attribs="true" msg="this is a message" ...>text here too</request> </...> The "text" enclosed within '<' and '>' must be replaced and the text not within '<' '>'...

What does this Perl regex do?

Can anyone please suggest me the meaning of below Perl regex: $_ =~ s/^([^,]+,)ab.([^,]+,)(?:[^,]+,)/$1$2/; What is the role of $1 and $2 and how these variables are defined? ...

How to validate an url on the iPhone

In an iPhone app I am developing, there is a setting in which you can enter a URL, because of form & function this URL needs to be validated online as well as offline. So far I haven't been able to find any method to validate the url, so the question is; How do I validate an URL input on the iPhone (Objective-C) online as well as offli...

SELECT only rows that contain only alphanumeric characters in MySQL

I'm trying to select all rows that contain only alphanumeric characters in MySQL using: SELECT * FROM table WHERE column REGEXP '[A-Za-z0-9]'; However, it's returning all rows, regardless of the fact that they contain non-alphanumeric characters. ...

Building dynamic Regex patterns in C#

I am trying to build a regex pattern with some parts of pattern retrieved from a database. For example string pt= "@\"\\b(" + db.GetPattern + ")\\b\""; Regex regex = new Regex(pt, RegexOptions.IgnoreCase | RegexOptions.Compiled); return regex.Replace(input, "*"); Although I tried to escape it, I couldn't get it to work. If I ...

Regular expression to lower a case

i'm retrieving the innerHTML in javascript let say element.innerHTML where all the tag are in Capital. i need to lower only the tag. using Regex or any inbuild methods.. ...

regex for triple quote

What regex will find the triple quote comments (possibly multi-line) in a Python source code? ...

Regex for Comma Separated Number or Just Number

This is something of a follow up from a previous question. The requirements have changed, and I'm looking for some help with coming up with regex for either a comma separated number or a number with no commas. Sample input is below, along with some failed attempts. Any help is appreciated. Acceptable input: 1,234,567 1234567 Unaccep...

Strip Tags thats are NOT in [code] [/code] segment

I'm trying to find a way to strip tags from a user-inputted string except from tags that are wrapped in the [code] [/code] BB style tag. For example, a user may enter this: <script>alert("hacked");</script> [code]<script>alert("hello");</script>[/code] What I would like is the "hacked" alert to be removed, but not the "Hello" alert. ...

in RegEx, can I "hardcode" named capture group's value

Is it possible to have a named capture group that will always have the value of "BLAH" despite "BLAH" not appearing in the string being matched? Effectively, I'm looking for something like the following pseudo-regex does (note the fake source=BLAH syntax): ^(?<source=BLAH>)$ ...

Error parsing regex pattern

I'm writing a simple regex in c# to locate backslashes not preceded or followed by any backslashes: Regex reg = new Regex(".*(?<!\\)\\(?!\\).*"); However, this statment generates an ArgumentException: "parsing ".(?" - Not enough )'s" The group parentheses seem to match. Can anyone spot the problem? ...

What is the regular expression to match the empty string for a rewrite rule?

I need a regular expression for a rewrite rule on iis7, I'm trying to redirect http://www.website.com to http://www.website.com/sample. But I only want the empty url string (extra points if you can figure it out with and without '/'), and I'm unsure how to create a rewrite rule to match to that. Can someone help me out here? ...