regex

How to specify the amount of characters to be matched?

Hello, I have these asset ID's in a CMS and I need to update them all with regular expresssions. They are 8 or 9 characters in length and made of all numeric characters (0-9). Is there a way to match only 8 or 9 numbers? I'm afraid I may not be using the right keywords in my google search to figure this out and I haven't found anythi...

Proper Perl syntax for complex substitution

I've got a large number of PHP files and lines that need to be altered from a standard echo "string goes here"; syntax to: custom_echo("string goes here"); This is the line I'm trying to punch into Perl to accomplish this: perl -pi -e 's/echo \Q(.?*)\E;/custom_echo($1);/g' test.php Unfortunately, I'm making some minor syntax error, an...

Need a Mod rewrite regex solution for .htaccess

I moved my site to different server since then my all urls started showing up 404 error. earlier my all urls were like this mysite.com/title-of-url but now all such urls are getting 404 error, so i disabled seo friendly url feature on site admin and now i can access same page on mysite.com/index.php/title-of-url i tired to create some...

Disabling backreferences in perl

I have been told that disabling backreferences in perl improves performance (provided you're not using them), and that if you don't use any backreferences perl will do this by itself. Now I have a perl script with a large number of regex in it and only a single one uses a backreference and I would like to know the following: Given I h...

Validate a name in Python

Hello, For an internationalised project, I have to validate the global syntax for a name (first, last) with Python. But the lack of unicode classes support is really maling things harder. Is there any regex / library to do that ? Examples: Björn, Anne-Charlotte, توماس, 毛, or מיק must be accepted. -Björn, Anne--Charlotte, Tom_ or entr...

getting empty array results using preg_match_all for values that don't match

I am using preg_match_all to search for HashTag values in a Twitter Search response. It works as I expected except for when the search results don't have any hash values in them. For some reason my $tags array still has values and I'm not sure why. Is it because my RegEx is not correct, or is it a problem with preg_match_all? Thanks ...

Regular expression isn't found in line: execution just hangs.

Hello all! I am new to python (and this site); I am trying to write a script that will use a regular expression to search through a given file to find a name. I have to print out the different ways the name was capitalized and how many times the name was found. My current code will just print out my first flag and then hang. I don't know...

How would you go about validating that a regex actually compiles and works, ie doesn't throw an error?

I'm creating an administration panel that has regex's submitted to it. Any ideas on how I would go about validating the submitted regex's to see if they work. When I say "see if they work" I mean if the regex's are valid and compile properly, not that they actually match data or not? FYI, This would be in PHP. ...

Regex to remove body tag attributes (C#)

Anyone has a regex that can remove the attributes from a body tag for example: <body bgcolor="White" style="font-family:sans-serif;font-size:10pt;"> to return: <body> It would also be interesting to see an example of removing just a specific attribute, like: <body bgcolor="White" style="font-family:sans-serif;font-size:10pt;"> ...

Get first part of string up to some string, that may or may not be in it...

Hi guys! I've got the following strings: Showname Showname - with hyphen Showname - Season 4 What I want is: Showname Showname - with hyphen Showname What I've come up with so far is: /(.*)( - season /d/d?)/i But that requires - season ?? to be in the string, which is not always the case... Any help would be r...

Regex to match tag contents while simultaneously omitting leading and trailing whitespace

I am trying to write a regex that matches entire contents of a tag, minus any leading or trailing whitespace. Here is a boiled-down example of the input: <tag> text </tag> I want only the following to be matched (note how the whitespace before and after the match has been trimmed): "text" I am currently trying to use...

regex - including strings: java

hi, I am trying to print out lines from a file which match a particular pattern in java. I am using the Pattern class for doing this. I tried putting the patter as "[harry]" so that every line which has "harry" gets printed out. But pattern always evaluates to false. My assumption is that the regex pattern I am entering is a string. M...

Regex help to match more than one letter

I am using the following regex to match an account number. When we originally put this regex together, the rule was that an account number would only ever begin with a single letter. That has since changed and I have an account number that has 3 letters at the beginning of the string. I'd like to have a regex that will match a minimum o...

How to replace all the Characters with * using Regular Expression

I am having a text like s = bluesky i want to get it as s = ******* (equal no of * as no of characters) I am searching for a regular expression for python. Plz help. Any help will be appreciated Edit 1 : b = '*'*len(s) How can we do it in Django Template ...

Where is the best place to define validation for a field?

A name field needs to be verified as starting with a capital letter and not being allowed to take a number. I'll do this with regular expressions. Implementing the MVC pattern. Should I have the controller send the value that was input to a checking class and send corresponding error msg's back to the UI and after checking then call t...

regex in Vietnamese characters

I have one string and want remove any character not in any case below: not in this list : ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼỀỀỂ ưăạảấầẩẫậắằẳẵặẹẻẽềềểỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪễệỉịọỏốồổỗộớờởỡợụủứừỬỮỰỲỴÝỶỸửữựỳỵỷỹ not in [a-z 0-9 A-Z] not is : _ and white space. can anyone help me with this regex in php? ...

Help required to solve this regex issue

I need to get all characters between a particular expression. For example below is my sample document This is a sample document. $if ( $variable) FIRST This text can be repeated many times until do while is called. $elseif($variable2) Some sample text follows this. $endif I need to get all the characters be...

internationalized regular expression in postgresql

How can write regular expressions to match names like 'José' in postgres.. In other words I need to setup a constraint to check that only valid names are entered, but want to allow unicode characters also. Regular expressions, unicode style have some reference on this. But, it seems I can't write it in postgres. If it is not possible ...

Java Regular Expressions using Pattern and Matcher

Hi All, my question is related to Regular Expressions in Java, and in particular, multiple matches for a given search pattern. All of the info i need to get is on 1 line and it contains an alias (e.g. SA) which maps to an IP address. Each one is separated by a comma. I need to extract each one. SA "239.255.252.1", SB "239.255.252.2...

Regular expression for grabbing the href attribute of an A element

Hi there Trying to find the links on a page. my regex is: /<a\s[^>]*href=(\"\'??)([^\"\' >]*?)[^>]*>(.*)<\/a>/ but seems to fail at <a title="this" href="that">what?</a> how would I change my regex to deal with href not placed first in the a tag? thanks! ...