regex

(rails) validating URL help with regexp

i'm using the following to verify if a URL is formatted validly: validates_format_of :website, :with => URI::regexp(%w(http https)) however, it doesn't work when the url doesn't start with http:// or https://. Is there some similar way to validate URLs with URI::regexp (or URI) and make it include valid URLs that don't start with http...

Regex with exception of particular words

Hi everyone, I have problem with regex. I need to make regex with an exception of a set of specified words, for example: apple, orange, juice. and given these words, it will match everything except those words above. apple (should not match) applejuice (match) yummyjuice (match) yummy-apple-juice (match) orangeapplejuice (match) orang...

Regex: finding several linebreaks

hi i'm having this html markup <body> <table border="0" width="50%" align="center"> <tr> <td> <center> and i'm trying to find a "wildcard" for the linebreaks to reach the <center> tag - how would this work? thx ...

/regex/(string) considered harmful?

In javascript you can match regular expression with regex(string) syntax. However the syntax isn't very used as far as I know, anybody know why? ...

Regex: remove lines not starting with a digit

I have been fighting this problem with the help of a RegEx cheat sheet, trying to figure out how to do this, but I give up... I have this lengthy file open in Notepad++ and would like to remove all lines that do not start with a digit (0..9). I would use the Find/Replace functionality of N++. I am only mentioning this as I am not sure wh...

String Dot String (Mail without Domain) RegEx

Hi mates, Really got stuck on this simple regex. Need it to validate a string, that will be a mail without the "@domain.xxx". It must accomplish the following rules: there must be a string (only letters) starting. there must be a string (only letters) ending. this two strings must be separated by a dot. the complete string mustn't co...

find regex pattern in Vim

some text i dont care about, some_text_I_want, <bunch of spaces> some_text_I_want, I want my pattern to match second line, not first line. Basically wherever some_text_I_want, is not preceeded with a , ...

test1 alert appears, test2 alert doesn't - invalid regex between them?

alert('test1'); var re = new RegExp("(http://(?:[A-Za-z0-9-]+\\.)?[A-Za-z0-9-]+\\.[A-Za-z0-9-]+/?)", "si"); alert('test2'); Why is this happening? How to solve this problem? ...

PHP Regex match first newline after x characters for a trimming function

I'm writing a trimming function that takes a string and finds the first newline \n character after the 500th character and returns a string up to the newline. Basically, if there are \n at indices of 200, 400, and 600, I want the function to return the first 600 characters of the string (not including the \n). I tried: $output = preg_r...

Capturing the first match with regex (C#)

Hello, This is my first experience with C# and part of my limited experience with regular expressions and I'm having trouble capturing the first occurrence of a match in a particular expression. I believe the following example would make it more clear than words in describing what I want to do. Match extractor = (new Regex(@".*\d(?<nam...

Automatic Documentation - Best method for creating a quick parser

I have a large script that end-users need to edit so it requires somewhat redundant commenting. I use a layout for my files similar to this //******************** // // FileName // This script contains: // - Function X - does something // - Function Y - does something else // //******************** //******************** // Fu...

How to determine if a string is a valid variable name?

I'm looking for a quick way (in C#) to determine if a string is a valid variable name. My first intuition is to whip up some regex to do it, but I'm wondering if there's a better way to do it. Like maybe some kind of a secret method hidden deep somewhere called IsThisAValidVariableName(string name), or some other slick way to do it tha...

Regex help: capture an entire line if it starts with a 1. or 2. ...

I'm awful at regexes, but would love some help defining a rule that would take this text: Il Cuccio, via Ronchi 43/b, 14047 Mombercelli, Asti. Tel: 380 7277050 Fax: 0141 959282 E-mail: [email protected] www.ilcuccio.it Accommodation in communal room or tent. French and English spoken. Contact: Cristina Belotti. Apicoltura Leida Bar...

How to validate digits (including floats) in javascript

Currently i'm using this reg exp: var valid = (value.match(/^\d+$/)); But for digits like '0.40', or '2.43' this doesn't work. How can I change that reg exp above to match floats as well? ...

Restricting a user to enter more than 7 digits before decimel and 3 after decimel

Hi, I want to get a user input from user in a textbox, but i need to validate it 1.It should not take more than 7 digits before decimel 2.it should not take more than 3 digits after decimel I actually figured out the 2nd part,,but first part is still a problem my regular expression is: /^([0-9]{0,7})+(\.[0-9]{1,3})?$/ Tell me whe...

ReplaceAll function in javascript

Hi all, I am getting a string "test+test1+asd.txt" and i want to convert it into "test test1 asd.txt" I am trying to use function str = str.replace("/+/g"," "); but this is not working regards, hemant ...

What's the shortest regex that can match non-zero floating point numbers with any number of decimal places?

What's the shortest regex that can match non-zero floating point numbers with any number of decimal places? It should accept numbers like -1 -5.9652 -7.00002 -0.8 -0.0500 -0.58000 0.01 0.000005 0.9900 5 7.5 7.005 but reject constructions such as . .02 -. -.996 0 -0 0. -0. -0.000 0.00 -- .. + +0 +1 +. +1.26 ,etc I do not need suppo...

Regex - If contains '%', can only contain '%20'

Hi All, I am wanting to create a regular expression for the following scenario: If a string contains the percentage character (%) then it can only contain the following: %20, and cannot be preceded by another '%'. So if there was for instance, %25 it would be rejected. For instance, the following string would be valid: http://www.tes...

Regex Question (detecting spam)

Hi all, I'm getting strange kind of spam, where the email body only contains this: 4606142 5801100 2704743 How can I grep this with regex? It's 3x7 numbers, separated with space. thx ...

Python regex matching Unicode properties

Perl and some other current regex engines support Unicode properties, such as the category, in a regex. E.g. in Perl you can use \p{Ll} to match an arbitrary lower-case letter, or p{Zs} for any space separator. I don't see support for this in either the 2.x nor 3.x lines of Python (with due regrets). Is anybody aware of a good strategy t...