regex

Regex named grouping

Can you have dynamic naming in regex groups? Something like reg = re.compile(r"(?PText|Or|Something).*(?PTextIWant)") r = reg.find("TextintermingledwithTextIWant") r.groupdict()["Text"] == "TextIWant" So that depending on what the beggining was, group["Text"] == TextIWant Updated to make the quesetion more clear. ...

Checking whole string with a regex

I'm trying to check if a string is a number, so the regex "\d+" seemed good. However that regex also fits "78.46.92.168:8000" for some reason, which I do not want, a little bit of code: class Foo(): _rex = re.compile("\d+") def bar(self, string): m = _rex.match(string) if m != None: doStuff() And...

Firewall blocking files using Reg_Ex needs to be adjusted

We have security in our firewall to prevent SQL-Injection from destroying any of our content: Name Type Context Severity Pattern Configure CS:select_into signature http-url critical .*\[select\].*\[into\].* Edit Remove CS:select_from signature http-url critical .*\[select\].*\[from\].* Edit Remove CS:insert_into sig...

Does Python re module support word boundaries (\b)?

Hi everyone While trying to learn a little more about regular expressions, a tutorial suggested that you can use the \b to match a word boundary. However, the following snippet in the Python interpreter does not work as expected: >>> x = 'one two three' >>> y = re.search("\btwo\b", x) y should have been a match object if anything wa...

Actionscript: Regular expression for file type checking

I want to check the file extension from the string using regular expression in action script. By googling, I find this, but I'm week to regular expression. Thanks. ...

Using FFMpeg to determine video-type, converting afterwards?

Hello, I'm trying to determine the real type of a file programmatically. It seems I have to use for example FFMPeg for that. I want to determine if an uploaded file is in fact a MP4 or FLV (for flash videos) [or WebM (for HTML5)]. I know the -i operator in FFMPeg but I don't know what to check for. For example: Input #0, flv, from ...

Simple find/replace using regex in Eclipse

I have the following possible lines in my code addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChangeHandler) addEventListener("click", propertyChangeHandler) addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, _propertyChangeHandler) addEventListener(PROPERTY_CHANGE, _propertyChangeHandler) They all have in common tha...

Generate a random number with specific format

I want to generate a 10 digit number, and non of its digit occur more than 3 times. ...

Will this regex patterns catch all the needed SQL injections?

We changed our firewall rules (REGEX) to the following: Name Type Context Severity Pattern CS:select_into signature http-url critical .*\[select\]\s+.*\[into\].* CS:select_from signature http-url critical .*\[select\]\s+.*\[from\].* CS:insert_into signature http-url critical .*\[insert\]\s+.*\[into\].* CS:drop_databa...

Python - Non-matching regex

Hey, I have the following regex: regex = compile("((?P<lastyear>[\dBFUPR]+)/)*((?P<lastseason>[\dBFUPR]+))*(^|-(?P<thisseason>[\dBFUPR]*))") Which I am using to process horce racing form strings. Sometimes a horses' form will look like this "1234-" meaning that it has not raced yet this season (there are no numbers to the right of th...

Help in set RegularExpressions in Delphi XE

hi, i want to set RegularExpressions for check string1. string1 can change to : string1:='D1413578;1038' string1:='D2;11' string1:='D16;01' ,.... in string1 only Character 'D' and semicolon is always exist. i set RegularExpressions1 := '\b(D#\;#)\b'; but RegularExpressions1 can't to check string1 correctly. in the vb6 this Regul...

Replacing ' by \'

How to convert ' in a string to \' in R? Example: from Bob's to Bob\'s ...

How to split a CamelCase string in its substrings in Ruby?

Dear Stackoverflow, I have a nice CamelCase string such as ImageWideNice or ImageNarrowUgly. Now I want to break that string in its substrings, such as Image, Wide or Narrow, and Nice or Ugly. I thought this could be solved simply by camelCaseString =~ /(Image)((Wide)|(Narrow))((Nice)|(Ugly))/ But strangely, this will only fill $1 a...

Python: Replace with regex

Hello, I need to replace part of a string. I was looking through the Python documentation and found re.sub. import re s = '<textarea id="Foo"></textarea>' output = re.sub(r'<textarea.*>(.*)</textarea>', 'Bar', s) print output >>>'Bar' I was expecting this to print '<textarea id="Foo">Bar</textarea>' and not 'bar'. Could anybody te...

PHP/PostGres regexp to match only if a word in the string has 2 or more capitals, and only has letters

This seems like a simple expression, but all of my tinkering has failed in one place or another. I am pulling data out of a PostgreSQL database. I would rather filter in PostgreSQL, but if I need to do it in PHP that is fine too. The column will have a string, and I need to search for matches where any word (defined by spaces) has two...

word boundary regex problem (overlap)

Given the following code: var myList = new List<string> { "red shirt", "blue", "green", "red" }; Regex r = new Regex("\\b(" + string.Join("|", myList.ToArray()) + ")\\b"); MatchCollection m = r.Matches("Alfred has a red shirt and blue tie"); I want the result of m to include "red shirt", "blue", "red" since all those are in the string...

Is it possible to write a regular expression to check this:

Is it possible to write a regular expression to check whether all numbers of specific 10 digit number occured up to 3 times? for example return value for Regex.IsMatch("xxxx", "4433425425") is false. and for Regex.IsMatch("xxxx", "4463322545") is true. what is xxxx? in the first one i have 4 occurrence of digit 4 and in second one non o...

grabbing text between two anchor words using jquery

Hi, I'm retrieving data from a form, using Jquery's ajax method. The data is coming back fine, and I can retrieve individual div elements by id or class. My problem is this - within one div I want to retrieve specific text occuring between two constant anchor words; this text occurs right at the start of the div. I've created a string...

[Python 3] Base64 decode until there is no Base64

Hello from Germany So my problem is something very simple, i think. I need to Decode Base64 until there is no Base64, i check with an RegEx if there is some Base64 but i got no Idea how to decode until there is no Base64. In this short Code i can Decode the Base64 until there is no Base64 because my Text is defined. (Until the Base64 D...

Convert line-broken paragraphs into single paragraphs? (Folding text?)

I have searched everywhere for an answer to this, but I think I must not be using the right lingo... I have text like this: This text is actually just one paragraph, but every few words are broken to a new line, and that's annoying as hell, because I have to go to each line and fix it by hand... Then there's a second paragraph which d...