Questions tagged [regex]

67563 questions
1

votes
2

answer
1k

Views

How to find with lookahead in Visual studio 2012 Regex Find and Replace

I am trying to find all using statements that are in cs files that contain a reference to a class anywhere in the file following it. For example, I want to match using Example.Foo; if BaseClass is found anywhere in the file following it. Like such: I've tried (using Example.Foo;)(?=[.\s\n]*BaseClas...
Jim
1

votes
1

answer
837

Views

Clean up img tags in a full html string

I have a full HTML string. It looks like this: This is a test What I would like to do is clean up the source. I want to remove all widths and heights in the img tags only. I want to preserve the ID and SRC attributes.
Bill Daugherty
1

votes
4

answer
160

Views

Print the column which contains only the mix of alphabets & numbers

Is there any one liner to print the lines which contain only the mix of alphabets & numbers in a file? I tried the following. But it doesn't work out. awk '{print $3}' test.log | grep -o '.[0-9][a-zA-Z]*' EDIT: Content of test.log: aaa bbb 1 ccc aaa mmm a1 nnn ooo bbb bc12 dm My intention here i...
SS Hegde
1

votes
1

answer
406

Views

strange AssertError when using fest regexp assert

I am getting this error - but the regex should imho match the string - would love to know what is the problem here java.lang.AssertionError: should match the regular expression: at org.fest.assertions.Fail.failure(Fail.java:228) at org.fest.assertions.Assert.failure(Assert.java:149) at org.fest.ass...
ligi
1

votes
3

answer
1.9k

Views

Regex to replace spaces and brackets with underscore

I have some strings in the following formats: this is a string This is a string This is a (string) This is a string and i want a regex convert it to the following: this_is_a_string with no leading I have the following using preg_replace which is getting me almost all of the way: preg_replace('/[^A-...
Marty Wallace
1

votes
1

answer
47

Views

exchanging Unicode char ruins char before this unicode char

I have a big list with unicode char's, which i want to exchange with some ASCII chars with following code (This code does some stuff more): while ($Zeile=) { @Zeile=split('\t',$Zeile); $i=0; foreach(@Zeile) { if ($i>1) { $entry=$_; $entry=~s/\(Details\)/ /; $entry=~s/\x{00BC}/.25/; $entry=~s/\x{00B...
Tigerle
1

votes
1

answer
55

Views

How to extract an Integral pattern out of a String using Regular Expressions

I am trying to make a mapLoader, which reads in a text file (here is an example) of the file [5,3,3,900,3,89,3,3,3,3,3,430,3,1439,3,65,3,320,3,3,3,3,3,3] [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,21,3,3,3,3,3] [5,3,3,900,3,89,3,3,3,3,3,430,3,1439,3,65,3,320,3,3,3,3,3,3] [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3...
Loligans
1

votes
7

answer
3.7k

Views

Javascript: String search for regex, starting at the end of the string

Is there a javascript string function that search a regex and it will start the search at the end? If not, what is the fastest and/or cleanest way to search the index of a regex starting from the end? example of regex: /]*>?/gi
Marl
1

votes
2

answer
98

Views

Expressing regular expression in words

I am trying to express the following regular expression in words. Please not this is not so much a programming regex, as opposed to some CS work I am doing. The regular expression is: (ab + b)* + (ba + b)* The spaces are meaningless and the '+' functions as an 'or'. My answer right now is: "This reg...
Tesla
1

votes
5

answer
1.5k

Views

Verify the domain of an e-mail address

I am writing a Python script that checks the inbox of an IMAP account, reads in those e-mails, and replies to specific e-mails. However, for security reasons I need to make sure that the original sender of the e-mail came from a particular domain. I am reading the e-mails in Python using the email...
Joseph
1

votes
2

answer
1.8k

Views

Regex capture lookbehind and lookahead

I'm trying to write regex for the following situations: badword% %badword %badword% The % signs differ, depending on where they are. A % at the front needs a lookbehind to match letters preceding the word badword until it reaches a non-letter. Likewise, any % that is not at the front needs a lookahe...
Brian Graham
1

votes
2

answer
58

Views

Get the matches from specific groups

I want to validate a String and, after that, get all the matches from some groups. RegEx: /^::=()+(\|()+)+$/ So, if I get something like ::=|| is valid, but if I get something like ::=| is false. There's no problem with the validation, the problem is that I want to take the text inside < and > becau...
Tomás Juárez
1

votes
2

answer
11.8k

Views

regular expression with limited special characters in jquery [closed]

I would like to all alphanumeric data + only these following 4 special character are allowed. ' (single quote) - (hyphen) . (dot) single space I tried this : var userinput = $(this).val(); var pattern = [A-Za-z0-9_~\[email protected]#\$%\^&\*\(\)]+$ if(!pattern.test(userinput)) { alert('not a valid'); }​ but...
patel
1

votes
4

answer
1.9k

Views

How to match multiple expression repeatedly by regexp in lua

I'm learning lua.There are some question in regexp. I have some string as: text = "aaab1aaac-aac1d2b5hhpt456d5h9h8" I want get result as: "b1", "c1b2b5", "t4", "d5h9h8" I write the code as the following. local st,ed while true do st,ed = string.find(text,"([a-z][1-9])+",ed) --the regexp if st==nil...
simon
1

votes
2

answer
3.7k

Views

Regular Expression: Double Backslashes in Bracket Expression

What do the double backslashes in the following expression match? /^[\\?]/ Is it a filter for \ and & (escaped backslash) - or - \\ and & (not escaped) - or - \ and ? (escaped question mark)?
headacheCoder
1

votes
1

answer
27

Views

Combine two regular expression into one while validating Attribute

I have two regular expression. [RegularExpression(@".*[^ ].*", ErrorMessage ="Something")] validate string that only contains spaces(Not any other characters Ex: " ".length = 7). [RegularExpression(@"^[^[email protected]#$%&*]+$", ErrorMessage = "something")] validate string that contains [email protected]#$%&* special...
Sipun
1

votes
1

answer
932

Views

Java Regex in round brackets

I am trying to parse an input string like this String input = "((1,2,3),(3,4,5),(2,3,4),...)" with the aim of getting an array of String where each element is an inner set of integers i.e. array[0] = (1,2,3) array[1] = (3,4,5) etc. To this end I am first of all getting the inner sequence with this...
lowcoupling
1

votes
1

answer
85

Views

C# Regular Expression - break text into specific pieces

Friends I am applying R.E @"^(.*)([0-9/+-^]+)=([0-9]+)$"on string "3u->4+5=8". While fetching Group[1] it returns "3u->4+" and Group[2] it returns "5". According to me, Group[0]="3u->4+5=8" Group[1]="3u->" Group[2]="4+5" Group[3]="8" Should be there. Kindly help
Pratik K. Shah
1

votes
1

answer
31

Views

Optional regular expression match

I have an string like 1566-02, where -02 is optional. If I use a regular expression like this 1566\s*-\s*\d{2} it will always expect 2 numeric number with hyphen after 1566. How I can make the -02 part optional, so that the IsMatch should be true for 1566 also? For example - The value of IsMatch sh...
user3260341
1

votes
3

answer
4.7k

Views

Regex - Allow alphanumeric, comma, period and space using PHP

I found many places where question like this are solved but I have no idea why is it not working for me. $reg = '/^[a-zA-Z0-9,. ]*$/'; // regex to allow only alphanumeric, comma, period and space $count = preg_match($reg, $arr[1], $matches); // verify regex if($count > 0){ $objArray[] = array($arr[0...
Roy
1

votes
2

answer
1.9k

Views

Splitting string using backslash using regex

For a python program I have an input that I am taking from stdin and the input is something like: "-------/--------\---------/------\" When I print it out as a string value it is printed as it is. I am trying to split the string into a list of strings based of forward and backward slash while keepi...
mbbce
1

votes
1

answer
1.2k

Views

unicode regular expressions c++

I want to match the word "février" or any other month by using regular expression. Regular expression: ^(JANVIER|FEVRIER|MARS|AVRIL|MAI|JUIN|JUILLET|AOUT|SEPTEMBRE|OCTOBRE|NOVEMBRE|DECEMBRE|Jan|Feb|Mar|Apr|May|Jun|JUN|Jul|Aug|Sep|Oct|Nov|Dec|[jJ]anvier|[Ff]évrier|[mM]ars|[aA]vril|[mM]ai|[jJ]uin|[j...
Hani Goc
1

votes
2

answer
1.4k

Views

Regex - nested lookahead assertion

suppose we want to match all one(s) between ... in this text (option: dot matches all): hello! home one living one text text one continues and at last here ends one dog one bye! let's say we use this pattern: one(?=(?:(?!).)*) I really appreciate it if someone explains how regex engine process that...
wiki
1

votes
1

answer
799

Views

how to traverse a unicode tamil word character by charcter in python?

I want to know how many characters are there in a Unicode string (Tamil) and then check the character1 and character2 for particular occurrences. I am able to split the word into characters, but I do not know how to traverse through them character by character using the word length. Example : word...
charvi
1

votes
3

answer
60

Views

String Manipulation with Regular Expression specifically or statements

I am trying to parse out certain strings from a phrase. This is the phrase: '1st Floor 2nd Floor 3rd Floor 4th Floor' The end phrase should be: '1st Floor','2nd Floor','3rd Floor','4th Floor' I am having trouble getting the '1st','2nd','3rd','4th' parts of the regex. I know I can do a less-intuitive...
user3683871
1

votes
5

answer
114

Views

Identifying the space in commas with regular expression

I have a data separated by spaces, but one of the data has special format with commas. For example: A B C,D,E,F G H The start of comma group is detected with "[^\s]+\,", and the end of the group is with "\,[^\s+]". In this example, the comma group starts with "C," and ends with ",F". The number of...
prosseek
1

votes
4

answer
668

Views

Is csv format regular grammar or context-free grammar?

I am currently writing a csv parser. The definition of csv format is given by RFC4180 which is defined by ABNF. So the definition of csv is absolutely a contex-free grammar. However, I would like to know if csv is regular grammar? So that I could parse it with just a finite state machine. Furthermor...
n3v3rm03
1

votes
1

answer
276

Views

In vs regular expressions for checking against a word blacklist — estimating expected production performance

I have many HTML pages in which I need to check the existence of blacklisted words. I know that the built-in in is much faster then regular expressions but here I'm trying to compare many in against a single regular expression. Since re.match() checks for a match only at the beginning of the string...
1

votes
1

answer
456

Views

Parse WHERE condition with regular expressions

I was wondering if anyone can help me with a regular expression - not my strongest point - to parse the WHERE part of a SQL statement. I need to extract the column names, either in "column" or "table.column" format. I'm using MySQL and PHP. For example, parsing: (table.column_a = '1') OR (table.colu...
motanelu
1

votes
1

answer
45

Views

Regex - Last mention

I'm using a Regex expression to extract mentions: /\[email protected][a-z0-9_-]+/gi. For the following string "Hi @andrew my username is @dan and I like cakes.", it will return : ['@andrew', '@dan'] What I would like is a Regex that get the last mention, with nothing after it: "Hi @andrew my username is @dan and I...
titibouboul
1

votes
3

answer
43

Views

Minus sign breaking equation extraction

I'm trying to make a regular expression that extracts the numerical constants and operators from an equation. For example, given the input X_1 + 1234 * 5678 + 2 (where X_1 isn't a constant, so it's ignored), I want to extract the 1234 * 5678 + 2. I have a regular expression that works for the above...
Mr. Llama
9

votes
1

answer
114

Views

re.sub(“.*”, “, ”(replacement)“, ”text") doubles replacement on Python 3.7

On Python 3.7 (tested on Windows 64 bits), the replacement of a string using the RegEx .* gives the input string repeated twice! On Python 3.7.2: >>> import re >>> re.sub(".*", "(replacement)", "sample text") '(replacement)(replacement)' On Python 3.6.4: >>> import re >>> re.sub(".*", "(replacement)...
Laurent LAPORTE
0

votes
0

answer
13

Views

iterate over file

I would like to iterate over a file and remove a series of lines that match a given regex. I have the script below but it only removes the 1st matching line/regex. How can i iterate through the file to get it to work? import glob import re read_files = glob.glob("*.agr") with open("out.txt", "w") as...
user3604308
1

votes
1

answer
21

Views

R string matching and replace

Starting with the string -theta[0] * x[0] * x[4] -theta[1] * x[1], I'd like capture theta[.] and replace with exp(theta[.]) giving the final result as: -exp(theta[0]) * x[0] * x[4] -exp(theta[1]) * x[1] How do I accomplish this in R? I tried the following to test by matching between as as follows: p
libby
1

votes
2

answer
1.6k

Views

c++11 regex : check if a set of characters exist in a string

If for example, I have the string: "asdf{ asdf }", I want to check if the string contains any character in the set []{}(). How would I go about doing this? I'm looking for a general solution that checks if the string has the characters in the set, so that I can continue to add lookup characters in t...
dk123
1

votes
2

answer
3.4k

Views

extract English words from string in python

I have a document that each line is a string. It might contain digits, non-English letters and words, symbols(such as ! and *). I want to extract the English words from each line(English words are separated by space). My code is the following, which is the map function of my map-reduce job. However,...
Jin
1

votes
1

answer
2k

Views

Get the word right before the coma with javascript and regex? [duplicate]

This question already has an answer here: capturing group in regex 3 answers Hi im trying to get the word right before the coma in a sentence. For example if the string is: "Cloudy, and 51 ° F " I want the output CLOUDY. How is this done in regex and javascript? I know you have to use the .match c...
gregyjames
1

votes
2

answer
470

Views

Oracle REGEXP_SUBSTR column names for PIVOT

I am working with PL/SQL Developer v10 on Oracle 11g database. In our system we have a question and answer table that I need to 'flatten' for each customer per question answered. One set of questions had specific code (PIFQ) in description of question that made the following script possible. Simply...
Matas Vaitkevicius
1

votes
2

answer
1.2k

Views

how to add ( ) brackets to characters after the first word in Notepad++

I need to put all the characters within brackets ( ) after the first word in a file, for example: g.setproperties "Title" "" "Comments" "" "UnitForce" "kN" "UnitLength" "m" "UnitTime" "s" g.bh 0 0 to g.setproperties ("Title" "" "Comments" "" "UnitForce" "kN" "UnitLength" "m" "UnitTime" "s") g.bh...
arudeepak
1

votes
2

answer
71

Views

Find the last occurrence of the end of a word

I have a string and I'm trying to find the last occurrence of an end of a word. E.G.: This is a test string and I need to find the last occurrence of a word. This sentence will be cut sho ^ I want to find the position of the space between cut and short I've tried using the end of word character symb...
Styphon

View additional questions