regex

how to match only once in regex perl

$line = " TEST: asdas :asd asdasad s"; if ($line =~ /(.*):(.*)/ { print "$1 = $2 " } I was expecting TEST =asdas :asd asdasad s but its not working ? what is issue ...

How to detect obtrusive text?

Many people are tired of obtrusive words with no value, like these: f**king Id|ot <|> whaaaat????!!!!??? I plan to detect suspicious records and then to verify them manually. In other words, to find rules which detect that something is most likely obtrusive. Is there any reasonable solution? I am thinking about these REGEX rules: \w...

Repeating a regex pattern

First, I don't know if this is actually possible but what I want to do is repeat a regex pattern. The pattern I'm using is: sed 's/[^-\t]*\t[^-\t]*\t\([^-\t]*\).*/\1/' films.txt An input of 250. 7.9 Shutter Island (2010) 110,675 Will return: Shutter Island (2010) I'm matching all none tabs, (250.) then tab, then all no...

Negative lookbehind in Python regular expressions

Hey, I am trying to parse a list of data out of a file using python - however I don't want to extract any data that is commented out. An example of the way the data is structured is: #commented out block uncommented block # commented block I am trying to only retrieve the middle item, so am trying to exclude the items with hashes a...

Regex - Group Value Replacement

I am not sure if this is possible to do, but I need a way to replace a value of a numbered group specified in the my regex expression with a string declared dynamically at runtime, once a match has been made. Given a simple case, something like... (/)?([A-Za-z0-9])?(/)?$ I would want to be able to plugin a replacement for group 2. I...

Bolden Matched Search Text

I'm writing a custom control which includes a text box input and an unordered list of items below it. As the user types in the text box I would like for the matched text in the list to be bolded (wrapped in <strong> tags). //I use keyup so the value takes in to account the last keystroke. $('#filterList').keyup(function() { ...

jQuery validating an CSV email array without the Validation Plugin...?

I have a textarea field that a user can upload a CSV file to populate the field. I then need to validate each one..here is the code I have but no luck: validateEmails = function(emailAddress){ var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; return reg.test(emailAddress); }...

C# word boundary regex instead of .Contains() needed

I have a list: var myList = new List<string> { "red", "blue", "green" }; I have a string: var myString = "Alfred has a red and blue tie"; I am trying to get a count of matches of words in myList within myString. Currently, I am using .Contains(), which gets me a count of 3 because it is picking up the "red" in "Alfred". I need to...

Getting Browser type with PHP

I'm trying to write a class that calls back certain functions for different browsers. What I want to do is create a switch statement that accepts either (CHROME, SAFARI, FIREFOX, MSIE, etc) that is pulled from a regular expression. I'm stumped on the regex part. I created named groups, but I can't figure out how to get the named group t...

detect cjk characters in a sentence using ruby!!

$str = "This is a string containing 中文 characters. Some more characters - 中华人民共和国 "; How do I detect if there are chinese characters in this string but i have no idea how to do it.Any clues? ...

Regex for everything before last forward or backward slash

Hey everyone, I need a regex that will find everything in a string up to and including the last \ or /. For example, c:\directory\file.txt should result in c:\directory\ Thanks! ...

Regexp matching a string pattern surrounded by capital letters

Hi, I would need one or more regular expressions to match some invalid urls of a website, that have uppercase letters before OR after a certain pattern. These are the structure rules to match the invalid URLs: a defined website zero, or more uppercase letters if zero uppercase letters after the pattern a pattern zero, or more upper...

extracting phone numbers

I'm trying to exract phone numbers from a set of data. It has to be able to extract international and local numbers from each country. The rules I've laid out for it are: 1. Look for the international symbol, indicating it's an international dialing number with a valid extension(from +1 to +999). 2. If the plus symbol is present, make ...

PHP Regular Expression Text URL to HTML Link

I'm working on a project where I need to replace text urls anywhere from domain.com to www.domain.com to http(s)://www.domain.com and e-mail addresses to the proper html <a> tag. I was using a great solution in the past, but it used the now depreciated eregi_replace function. On top of that, the regular expression used for such function ...

Differences between C# and JavaScript Regular Expressions?

Are C# and JavaScript Regular Expressions different? Is there a list of these differences? ...

url rewrite regex question

My regex expression for isapi rewrite here isn't passing variables in the URL Trying to pass a variables like: www.domain.com/z34232/ProductName.html?ref=magic But the code is ignoring the "ref=magic" string RewriteRule .*z([[:digit:]]*)\/.*.html\??(.*) /product.asp\?pnum=$1(?2&$2&:) [I,O,L] Any suggestions would be extremely h...

How should i get complex numbers from string?

I found following pattern from RegexLibrary, and i don't know how use Match to get Re and Im values. I'm new in Regex. Is it a correct way to get data from a pattern? If it's true, I need some sample code! This is what i think it should be: public static complex Parse(string s) { string pattern = @"([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][...

Regular Expressions - extract URL within string

I have a string with roughly 2k URLs embedded in it and need help with regular expression pattern to extract the URLs. Example of string with URLs embedded "blahblahblah;http://subdomain.server.com/index.asp?id=1000;blahblahblah;" The URL will always begin with "http://subdomain.server.com/" and end with the first ";". The only thin...

Regex, add an attribute to a tag in html (php).

Hi, I can't quite figure it out, I'm looking for some regex that will add an atttribute to a html tag. For example lets say I have a string with an <a> in it, and that <a> needs an attribute added to it, so <a> get's added style="xxxx:yyyy;" . How would you go about doing this? Ideally it would add any attribute to any tag. Am I aski...

Finding quote marks within alt tags

I'm wondering how I would approach the following problem with regular expressions. We run into the occasional problem of quote marks (") inside Alt tags which can cause rendering issues. Would it be possible to write a regular expression to find Img tags, but only when the ALT contains quotes? For example these would be found <img src...