FAQ Database Discussion Community


Adding and Subtracting numbers from a String

java,regex,string,delimiter
This program takes in a string and adds up all the integers in it, I have set the delimiter to be "+" surrounded by any amount of white space. It works fine with that but now I want it to work with any negative integers as well, for instance if...

Patterns (preferably java) find floor space in sq ft

java,regex,pattern-matching
I have the following data that needs parsing. The pattern could be (1) approx 1,000 sq ft (2)c. 500sqft (3) 2,100 sq ft This is my code to find a digit but I need the above... in java Pattern regex = Pattern.compile("\\d[\\d,\\.]+"); Matcher finder = regex.matcher(price); if(finder.find()){ try { String...

After removing bullet points using regex getting extra space between characters

javascript,regex
I am using regular expression to remove certain set of things like bullet points from my text and I am able to remove that using the following code: mystr = mystr.replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, ' '); But unfortunately when I am giving text for example "abc def" I am getting extra...

REGEX python find previous string

python,regex,string
I'm trying to find if the last word of the string is followed by a space or a special char, and if yes return the string without this space/special char For example : "do you love dogs ?" ==> return "do you love dogs" "i love my dog " (space...

regular expression in sublime text 2 to match text

regex,sublimetext2
I have a string that looks like this: lonfksa.newsvine.com and I have tons of file that looks like this: http://ricambi.ru/avtomobilnie-novosti/lexus-gotovit-k-debiutu-obnovlenniy-rx http://www.kiwibox.com/hoytboar/blog/entry/121424391/modis-tshirt-tips-untuk-womens-clothing/ http://www.euro-rockradio.com/archives/category/interview http://lonfksa.newsvine.com/_news/2014/04/18/23538711-vampir-romantis-clothing...

Java - Enforce TextField Format - UX - 00:00:00;00

java,regex,user-interface
Please see below image of the UI of my current application Currently, I am enforcing Data Format of the text fields in the back end. If the RegEx does match (00:00:00;00), it will throw an error. My question is from a UX perspective, is it possible to make the input...

RegExp to check if file is image

javascript,regex
Is there a way to know if the file extension is an image? i got this. image/png Already try with var imageReg = /\.(gif|jpg|jpeg|tiff|png)$/i; string = "image/png" imageReg.test(string) But this return false;...

I need to make sure that only certain characters are in a list?

python,regex,string,list,python-2.7
I have this to get input and put it in a list: def start(): move_order=[raw_input("Enter your moves: ").split()] And I only want the characters A, D, S, C, H (it's for a game >_>) to be allowed. I've tried using the regular expressions stuff: if re.match('[ADSCH]+', [move_order]) is False: print...

Regular expression to replace spaces between numbers with a comma

regex,sublimetext
I have a huge list of the following in a large file that contains information about every country in the world. They are arrays of temperature data, sometimes the spaces vary in length. [23.5 26.3 29.3 31.9 32.8 31.2 28.8 27.8 28.4 29 26.6 23.7] I'm attempting to use sublime...

How to Match a string with the format: “20959WC-01” in php?

php,regex
i want to restrict a user to enter a value which is similar to the value "20959WC-01", means it must contains 5 integers followed by two character, a '-' and two integers, can anyone please give me a solution to sort out this problem. Thanks in advance :) ...

Identify that a string could be a datetime object

python,regex,algorithm,python-2.7,datetime
If I knew the format in which a string represents date-time information, then I can easily use datetime.datetime.strptime(s, fmt). However, without knowing the format of the string beforehand, would it be possible to determine whether a given string contains something that could be parsed as a datetime object with the...

Negate a specific group in regular expressions

regex,vb6
How do you get a string not containing a specific group? (?:[0-9-+*/()x]|abs|pow|ln|pi|e|a?(sin|cos|tan)h?)+ Above string is the expression for mathematical expressions. How do you get the string that is not a mathematical expression? Example:WIDTH+LENGTH*abs(2) Supposed Output: WIDTH LENGTH...

How to write RegEx for inserting line break for line length more than 30 characters?

regex
I am using a text editor which lets use regular expression to find / replace text. I have a large text file. I want to insert new line in each lines which are more than 30 characters. I want the line to break after 30th character (doesnt matter if a...

why split() produces extra , after sets limit -1

java,regex,split
I want to split Area Code and preceding number from Telephone number without brackets so i did this. String pattern = "[\\(?=\\)]"; String b = "(079)25894029".trim(); String c[] = b.split(pattern,-1); for (int a = 0; a < c.length; a++) System.out.println("c[" + a + "]::->" + c[a] + "\nLength::->"+ c[a].length()); Output:...

Finding embeded xpaths in a String

java,regex
I have a string where I have the user should be able to specify xpaths that will be evaluated at runtime. I was thinking about having a the following way to specify it. String = "Hi my name is (/message/user) how can i help you with (/message/message) "; How can...

Find any character occur more than 4 times

sql,regex,oracle
I want to find any character occurs between 4 and 10 times, I used REGEXP_LIKE but it's valid just for one character 'a' , I want to find for all alphabet: SELECT regex_test_name FROM regex_test WHERE REGEXP_LIKE(regex_test_name, 'a{4,10}') ...

regex to pull in number with decimal or comma

ruby,regex
This is my line of code: col_value = line_item[column].scan(/\d+./).join().to_i When I enter 30,000 into the textfield, col_value is 30. I want it to bring in any number: 30,000 30.5 30.55 30000 Any of these are valid... Is there a problem with the scan and or join which would cause it...

how to select the first number in a link

php,regex
I have a link, something like this: $link = 'http://www.example/data/showall.php?quantity=&lang=eng&sura=2&ayat=21'; Now I want the first number of it, In this case I want 2. Note: All characters are fixed except the numbers. To simplify my string, I can replace the first of it with empty, something like this: $link ='2&ayat=21';...

jQuery / Regex: How to compare string against several substrings

jquery,regex,string,substring,substr
I have a special validation need where I need to check if a string contains ANY out of several substrings like the following list: 12 23 34 45 56 67 78 89 90 01 I am new to jQuery and the only thing I could think of here is the...

Regex with whitespaces and preceding zeros

regex,sas
I want to match the string 11 with a regular Expression in SAS. The 11 can be preceded by zero or more 0 and/or by white spaces. Any other character is not allowed. Likewise, if anything there should only be white spaces following the 11. Examples: Match: 0000011 11 11<space><space>...

Matching multi-line text

php,regex
I have the following text: [FONT=arial, helvetica]this is a multiline text [/FONT] [FONT=arial, helvetica] this is a single line comment[/FONT] I'm trying to match the text inside the bbcode tags with this pattern: \[FONT=(.*?)\](.*?)\[\/FONT\]\im But it only matches the single line text, why? I've even added the multi-line flag. http://www.regexr.com/3b72f...

Ruby gsub group parameters do not work when preceded by escaped slashes

ruby,regex
I am trying to perform a trivial substitution, that in any other language I have come across, work as per the documentation. However, my substitution fails for some reason. The documentation examples list: "hello".gsub(/[aeiou]/, '*') #=> "h*ll*" "hello".gsub(/([aeiou])/, '<\1>') #=> "h<e>ll<o>" "hello".gsub(/./) {|s| s.ord.to_s + ' '} #=> "104 101...

Python regex sub named captured

python,regex
I missing something very basic here. I want to match all instances of, for instance, throw 'some string' or throw "error here". p = re.compile(b'throw ["|\'](?P<err>).*["|\']') This seems to work fine for matching. But, for instance, I want to replace throw 'some string' with, for instance, throw new Error('some string')....

Extracting strings from HTML with Python wont work with regex or BeautifulSoup

python,regex,parsing,beautifulsoup,python-requests
Im using Python 2.7, BeautifulSoup4, regex, and requests on windows 7. I've scraped some code from a website and I am having problems parsing and extracting the bits I want and storing them in a dictionary. What I'm after is text that is presented as follows in the code: @CAD_DTA\">I...

Why have two '\' in Regex? [duplicate]

javascript,regex
This question already has an answer here: Extra backslash needed in PHP regexp pattern 4 answers Regex to replace single backslashes, excluding those followed by certain chars 3 answers Why do regex constructors need to be double escaped? 4 answers function trim(str) { var trimer = new RegExp("(^[\\s\\t\\xa0\\u3000]+)|([\\u3000\\xa0\\s\\t]+\x24)", "g");...

Regular expression for class using Beautifulsoup

python,html,regex,beautifulsoup,html-parsing
I am using Beautifulsoup for easy scraping. I have figured out there are more than 5 div in webpage which I want to scrap. Their names are different but has pattern. These divs are: divnewthing divnew divnewstring etc So the pattern is divnew* kind of regular expression. And I am...

Swing regular expression for phone number validation

java,regex
I want to validate phone number field in swing, so I am writing code to allow user to enter only digits, comma, spaces. For this I am using regular expression, when user enter characters or other than the pattern text field will consume. My code is not working. Can anyone...

MySQL function with parameters syntax error

mysql,regex,function
I'm trying to convert this query to a MySQL function SET @v1 := ( SELECT count(id) as count FROM article_category where (title like "About Usd") or (title like "About Usd-%" and title regexp '[0-9]$') ); INSERT INTO `article_category` (`title`,`meta_data`,`meta_description`) VALUES ( IF(@v1 <= 0, "About Usd", CONCAT("About Usd","-",@v1) ), "ddddD",...

Htaccess rewrite URL with virtual directory and 2 variables

regex,apache,.htaccess,url,rewriting
its my URL... result.php?team=arsenal&player=ospina I want to like this mysite.com/virtualdirectory/arsenal/ospina.html I tried this code.. cant work.. Not Found RewriteRule ^(.*)/(.*)/(.*).html$ result.php?team=$2&player=$3 [L] The requested URL /subfolder/arsenal/ospina.html was not found on this server. Apache/2.2.8 (Win32) PHP/5.2.6 Server at localhost Port 80 Thanks for helps, Best regards!!...

Please can someone help me understand the exec method for regular expressions?

javascript,regex
The best place I have found for the exec method is Eloquent Javascript Chapter 9: "Regular expressions also have an exec (execute) method that will return null if no match was found and return an object with information about the match otherwise. An object returned from exec has an index...

Regex first ends with jpg|jpeg|gif|png

python,regex
So I have this regex: https?://[^/\s]+/\S+\.(?:jpg|jpeg|gif|png) And am using it on this text: [url=http://www.gameoverse.com/wp-content/uploads/2015/05/Nintendo-World-Championship-2015-News-1024x576.jpg]http://www.gameoverse.com/wp-content/uploads/2015/05/Nintendo-World-Championship-2015-News-1024x576.jpg[/url] En tråd för oss som sitter uppe i natt och vill diskutera vad som händer i tävlingen.  Det ska tydligen spelas oannonserade spel så det här ska bli kul :D  Länk till sändningen:...

How do I isolate the text between 2 delimiters on the left and 7 delimiters on the right in Python?

python,regex,string,split
I have a string: string = ""7807161604","Sat Jan 16 00:00:57 +0000 2010","Global focus begins tonight. Pretty interested to hear more about it.","Madison Alabama","al","17428434","81","51","Sun Nov 16 21:46:24 +0000 2008","243" I only want the text: "Global focus begins tonight. Pretty interested to hear more about it."" which is between the 2nd and...

Regex that allow void fractional part of number

c#,regex
@"[+-]?\d+(\.\d+)?" -this is a regex I have wrote for numbers it allows [+-] minus before the number digits before and digits after the point the question is how to change this to allow "not finished" values so that input of "5." - is fine too ?...

Reg ex matching a word

regex
I need to match only first two files, out of four files listed below: ABD_DEF_GHIJ_20150611 ABD_DEF_GHIJ ABD_DEF_GHIJ_FX_20150611 ABD_DEF_GHIJ_FX I am using reg ex - ABD_DEF_GHIJ(_\d{8}|\b) and it's working fine. I would like to know if my solution is ok or there is any better alternate solution....

Replace regex matches in a string with items from a list in order

python,regex
For example, I've got a string like: 'blah blah 1.344 blah 1.455' and a list like: [2.888, 4.033] I know that the string and the list contain an equal quantity of numbers and want to replace all the numbers in the string with the numbers from the list using regex....

match line break except line begin with spcific word or blank line

regex,notepad++
If I have text that the line breaks is broken: Chapter 1 Lorem ipsum dolor sit amet, consectetur adipisci ng elit, sed do eiusmod tempor incididunt ut la bore et dolore magna aliqua. Ut enim ad minim ve niam, quis nostrud exercitation ullamco labo ris nisi ut aliquip ex ea...

format currency regular expression javascript

javascript,regex
I need to display a formatted number on a web page using JavaScript. I want to format it so that there are commas in the right places. How would I do this with a regular expression? I've gotten as far as something like this: I am trying to use regular...

Regex not working in HTML5 pattern

regex,html5
So I have this regex intended to let pass all text but those that contain as initial chars the "34" sequence: ^(?!34)(?=([\w]+)) The regex is working fine for me in https://regex101.com/r/iN1yN3/2 , check the tests to see the intended behavior. Any Idea why it isn't working in my form? <form>...

using sed to replace a line with back slashes in a shell script

regex,bash,shell,ssh,sed
I am trying to replace the bottom one of these 2 lines with sed in a file. <rule>out_prefix=orderid ^1\\d\+ updatemtnotif/</rule>\n\ <rule>out_prefix=orderid ^2\\d\+ updatemtnotif/</rule>\n\ And the following command seems to do that when executed as a command at the bash prompt sed -i [email protected]_prefix=orderid ^2\\\\d\\+ [email protected]_prefix=orderid ^2\\\\d\\+ [email protected]' /opt/temp/rules.txt however, when...

How many characters are visible like a space, but are not space characters?

php,regex
If I want to discover the hexadecimal equivalent of a space in PHP I can play with bin2hex: php > echo var_dump(bin2hex(" ")); string(2) "20" I can also obtain space character from "20" php > echo var_dump(hex2bin("20")); string(1) " " But there exist Unicode versions of a "visible" space: php...

JS regex for match sentence

javascript,regex
I'm not able to create a regex for correctly match single sentences in a text with javascript. I've used /([!?.:])\s+/g but doesn't match a correct sentence in a long sequence. For example [1](I have received a big present!) [2](You know?) [3](it's, really, a car.) [4](The car have: a blue color)...

regex - Match filename with or without extension

regex,logstash-grok
Need a regex pattern to match all of the following: hello hello. hello.cc I tried \b\w+\.?\w+?\b, but this doesn't match "hello." (the second string mentioned above)....

How is the order of a re.search determined?

python,regex
assuming I have a pattern resembling: re.compile(r"(pattern1)|(pattern2)|...|(patternN)") Where the patterns are intentionally ordered by some method. I expected the search order to be left to right returning the first match, but the results have proven otherwise. How is the order of the pattern search determined? EDIT: This may very well...

Replace multiple numbers with other numbers in a string using REGEX c#

c#,regex,string
so I have hundreds of these lines below( i trimmed alot), I want to capture the DEFAULT value and set to 0.99 but only for the lines WITH <Movement display_name="Movement type can be session or system ,independent of type and min and max, I am new to REGEX, this is...

Is there a database that can store regex as values?

regex
I am looking for a database that can store regex expressions as values. E.g. somthing like this: {:name => "Tim", :count => 3, :expression => /t+/}, {:name => "Rob", :count => 4, :expression => /a\d+/}, {:name => "Fil", :count => 1, :expression => /tt/}, {:name => "Marc", :count => 1,...

How to use regex to search in a string

python,regex
I am now using regex to handle some string, now I have a special string that is not easy to use regex to handle. below are some sample string. TP-LINK is a sample, it can be other router vendor with similar format. TP-LINK Wireless Range Extender WA810RE TP-LINK Wireless WA850RE...

Validate part of mail suffix

c#,regex
I'm validating mail addresses that could look something like this: [email protected] but also [email protected] I would like to check whether if xx is present or not. The first thing that came to mind was String.Contains, but it would obviously match any occurrences of xx in the string. Is regexp the...

Python regular expression, matching the last word

python,regex,list
I've the following problem. I'm looking to find all words in a string that typically looks like so HelloWorldToYou Notice, each word is capitalized as a start followed by the next word and so on. I'm looking to create a list of words from it. So the final expected output...

Store regex pattern as a string in PHP when regex pattern contains both single and double quotes

php,regex
UPDATE: It turned out that what broke my reg expressions after escaping the quotes was the / deliminator terminating the expression early. I'm attempting to store a regex pattern as a string like so: $link_pattern = "/<a\s+href=(?:"([^"]+)"|'([^']+)').*?>(.*?)</a>/"; However I'm unable to properly encapsulate it since the regex pattern contains both...

Java Matcher.replaceAll() matches group(0) elements as well

java,regex
I think this is a very common problem, but couldn't find a related question in SO or any other tutorial as well. So if it's a duplicate, feel free to mark as such. Well here is the problem, I have a String and I would like to replace all the...

lookbehind for start of string or a character

regex,python-2.7,regex-lookarounds
The command re.compile(ur"(?<=,| |^)(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE) throws a sre_constants.error: look-behind requires fixed-width pattern error in my program but regex101 shows it to be fine. What I'm trying to do here is to match landmarks from addresses (each address is in a separate string) like: "Opp foobar, foocity" --> Must match...

JavaScript Regex: Escape the string “c++”?

javascript,regex,escaping
I'm working on some regex for a input text field and have had some trouble escaping special characters such as "+" or "?". I've used these two questions for doing so and they work for a string such as c+ but if I enter c++ I get following error in...

BeautifulSoup: Parsing bad Wordpress HTML

python,html,regex,wordpress,beautifulsoup
So I need to scrape some a site using Python but the problem is that the markup is random, unstructured, and proving hard to work with. For example <p style='font-size: 24px;'> <strong>Title A</strong> </p> <p> <strong> First Subtitle of Title A </strong> "Text for first subtitle" </p> Then it will...

Remove plus sign from url using .htaccess

php,regex,apache,.htaccess,mod-rewrite
My current url is: http://localhost/mywbsite/search/one+piece/149 I want to change link to like this http://localhost/mywbsite/search/one-piece/149 I have already .htaccess file with this code Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] I don't know where to change to remove plus(+) sign...

chunk of data into fixed lengths chunks and then add a space and again add them all as a string

regex,list,join,ironpython,findall
I have got hex values as a85b080040010000. I want it to be as a8 5b 08 00 40 01 00 00. I have done it by using below code. But I have to work with very large data. So I want computed time to be very low. import binascii import...

Pandas add column to df based on list of regex patterns

python,regex,pandas
I have a dataframe that looks like this: Sentence bin_class "i wanna go to sleep. too late to take seroquel." 1 "Adam and Juliana are leaving me for 43 days take me with youuuu!" 0 And I also have a list of regex patterns I want to use on these...

Regex to match ASCII Table character with decimal value

regex,decimal,ascii
So I need a Regex to match the ASCII character STX(Start Of Text) which is number 2 on ASCII Table. I tried ^ as Regex101.com suggest for start of text but it was unsuccessful. Then I tried [[:ascii:]] which was matching for all ASCII characters. Is there any way to...

Regex pass dynamic values with boundry

c#,regex,string,boundary
I'm trying to pass a dynamic value at runtime with a boundary \b to a Regex function. My code is: static void Main(string[] args) { string sent = "Accelerometer, gyro, proximity, compass, barometer, gesture, heart rate"; string match = "gyro"; string bound = @"\b"; if (Regex.IsMatch(sent, @"\bgyro", RegexOptions.IgnoreCase)) { Console.WriteLine("match...

Python match whole file name, not just extension

python,regex,nsregularexpression
Objective: Use Python regex to return a list of filenames have certain file extensions. List of files: X8SIA9.ROM X8SIA0.rom X8SIA0.928 Regex to find files that end in *.ROM or 3x numbers: bios_file = re.findall(r'.*\.(rom|[0-9]{3})+', name, re.I) Issue: bios_file is returning ['ROM'], ['rom'], [928]. bios_file should be returning the entire filename...

How to create the javascript regular expression for number with some special symbols

javascript,regex
what can be the java-script regular expression which gives the numbers with some symbols For example following condition must be pass. Number can start with $ Can have the . or , : symbols between and % sign at the send. Passing valus: $233 48.23% 278 22.33 45:23 10,000 Number...

Coloring Text in JTable Cell

java,regex,swing,jtable,tablecellrenderer
I want to color text in a JTable cell. I'm using a DefaultTableCellRender with HTML Tags to color multible words/text. I'm using Regex to find words/text and replacing them by adding HTML Tags. The problem here is that the HTML tags them selves should not match by the regex. example:...

Split by a comma that is not inside parentheses, skipping anything inside them

java,regex,string,split
I know it might be another topic about regexes, but despite I searched it, I couldn't get the clear answer. So here is my problem- I have a string like this: {1,2,{3,{4},5},{5,6}} I'm removing the most outside parentheses (they are there from input, and I don't need them), so now...

Regular Expression Test100-200

regex
For powershell v3 i need to find items in the range of Test100 to Test200. For example it should work as this; Test001 - not valid Test099 - not valid Test100 - valid Test150 - valid Test200 - valid Test201 - not valid I tried -match (Test[100,200]) but this does...

How to define a Regex in StandardTokenParsers to identify path?

regex,scala,parsing,lexical-analysis
I am writing a parser in which I want to parse arithmetic expressions like: /hdfs://xxx.xx.xx.x:xxxx/path1/file1.jpg+1 I want to parse it change the infix to postfix and do the calculation. I used helps from a part of code in another discussion as well. class InfixToPostfix extends StandardTokenParsers { import lexical._ def...

Pharo punctuation marks [duplicate]

regex,pharo,punctuation
This question already has an answer here: Learning Regular Expressions [closed] 1 answer Is there any way to capture all the places in a String, where there are punctuation marks like '.,:;!?' Basically, am looking for a regex that captures all the above....

MySQL substring match using regular expression; substring contain 'man' not 'woman'

mysql,regex
I have an issue while I fetch data from database using regular expression. While I search for 'man' in tags it returns tags contains 'woman' too; because its substring. SELECT '#hellowomanclothing' REGEXP '^(.)*[^wo]man(.)*$'; # returns 0 correct, it contains 'woman' SELECT '#helloowmanclothing' REGEXP '^(.)*[^wo]man(.)*$'; # returns 0 incorrect, it can...

How to get negative lookahead in regex to accept more words

regex,splunk
I am trying to get some data for Splunk. From this: this my line - Fine (R/S) more date - I like this (not) date - output (yes) I like to get all data from - to the end of line, but not the data in parentheses if it contains...

Split by a word (case insensitive)

python,regex,string,split
If I want to take "hi, my name is foo bar" and split it on "foo", and have that split be case insensitive (split on any of "foO", "FOO", "Foo", etc), what should I do? Keep in mind that although I would like to have the split be case insensitive,...

Regex in Perl Uninitialized $1

regex,perl
My string looks like this: <File `../Path/To/My_File.gif'> I want to extract just "Path/To/My_File.gif". Here is the check I have: if ($row =~ /(?<=File `..\/).*(?=')/) { print "Found it!\n"; print "$1\n"; } I see "Found it!" printed to the console but also get an error saying that $1 is uninitialized. What...

How to match words in 2 list against another string of words without sub-string matching in Python?

python,regex,string,loops,twitter
I have 2 lists with keywords in them: slangNames = [Vikes, Demmies, D, MS Contin] riskNames = [enough, pop, final, stress, trade] i also have a dictionary called overallDict, that contains tweets. The key value pairs are {ID: Tweet text) For eg: {1:"Vikes is not enough for me", 2:"Demmies is...

Match a pattern preceded by a specific pattern without using a lookbehind

regex,eclipse,lookahead
Is there a way to match a B only if preceded by an A? The A can be at any position behind the B, with any amount of characters between. Examples: A_B (Matches `B`) C_B (No match) I've tried: (?=A)[^B]*B But it matches all the characters preceeding B as well....

Regular Expression for whole world

regex,c#-4.0,vb6
First of all, I use C# 4.0 to parse the code of a VB6 application. I have some old VB6 code and about 500+ copies of it. And I use a regular expression to grab all kinds of global variables from the code. The code is described as "Yuck" and...

PHP preg_match - regular expression

php,regex,preg-match
I have this text: SU4R C45G G3HD 61U14XE7AR23 914K16W471LV V6SQ5V16LG91 24YL4HW956C3 UZ26J12K615V T741MH4N739W 31ST445G726H 621EH6VW7Q6M 55N629WJ945P 56TX2W6LC949 44DS765CF739 XC262HV1JZ6V 26YD4N1Y71F7 S4M3F1XeDC0D I want to use preg_match to find specific type of code in that text, so I should contains: 4 or 12 characters it should returs all elements non case...

take words out of string with Reg

regex
Sorry, I am not a reg expert. I would like to ask for help how to take certain words out of a string. Here is a example, I have a long string like this: [SubClassOf(<file:F:/Projects/OIL/DAMLOilEd/ontologies/ka.daml#Lecturer> <file:F:/Projects/OIL/DAMLOilEd/ontologies/ka.daml#Person>)] I need to extract the words Lecturer and Person out of the long string....

Get all prices with $ from string into an array in Javascript

javascript,regex,currency
var string = 'Our Prices are $355.00 and $550, down form $999.00'; How can I get those 3 prices into an array?...

Replace improper commas in CSV file

regex,r,csv
This may have been asked before, but I couldn't find it. I have a list of CSV files (439 or so) where, in a few of the files, someone also used commas in editorial comments. The result is that I can't put the files into a data frame, since the...

Find numbers in a file and change their value with perl

regex,perl
I have a file with some data in it but there are a bunch of annoying numbers that are less than one which I wanted to just change to 1 instead of manually doing it. I was wondering how you would do this in perl. I tried using something like...

Regex to remove `.` from a sub-string enclosed in square brackets

c#,.net,regex,string,replace
I have this regex in C#: \[.+?\] This regex extracts the sub-strings enclosed between square brackets. But before doing that I want to remove . inside these sub-strings. For example, the string hello,[how are yo.u?]There are [300.2] billion stars in [Milkyw.?ay]. should become hello,[how are you?]There are [3002] billion stars...

Regex for one, two, three etc using Node.js

regex,node.js
I am working on regex and facing one problem. I am not able to finding one, two, three, four etc. in string using regex in node.js. Example: String contains some time Chapter 1 or Chapter one. I can find 1 but not one. Chapter one Chapter two Chapter three Chapter...

Find a regex to take part of Email

php,regex
I have the following emails I need to extract a part from: Bestellnummer xxx: 1 von xxx, 1er Pack ------------- Anfang der Nachricht ------------- foo bar baz foo bar baz // <<<<< I need this text here ------------- Ende der Nachricht ------------- ------------- Anfang der Nachricht ------------- foo bar baz...

like and regexp_like

sql,regex,oracle,oracle11g,regexp-like
For like we have %. for ex: if we give ad% it ll fetch all the records which starts with ad but i should use regexp_like. for regexp_like what can be used so that it acts as % for like. i cant use ^ad because from UI we ll give...

Regex result capturing case

c#,regex
If I have input strings of the type ((a|b)\\.([a-zA-Z]+)|c), how must I do the capturing of split results so that the following test cases work? a.hello yields '', 'a', 'hello', '' b.tmr yields '', 'b', 'tmr', '' c yields '', 'c', None, '' Thanks...

Get number from string

regex
I am trying to get the enclosed number between two slashes in a URL using regex. The code regex I have is not working, I am fairly new to regex and don't really understand it. The regex: http:\/\/?www\.?example\.com\/g\/(^\d$)\/\w The URL: http://www.example.com/g/1337/Game-Title Trying to get the "1337", which is the PlaceId....

String#scan not capturing all occurences

ruby,regex
I'm facing a very strange behaviour with ruby String#scan method return. I have this code below and I can't find out why "scan" doesn't return 2 elements. str = "10011011001" regexp = "0110" p str.scan(/(#{regexp})/) ==> [["0110"]] String "str" clearly contains 2 occurences of pattern "0110". I want to fetch...

Regular expression to get url in string swift

ios,regex,swift
I try to get urls in text. So befor I used such expression let re = NSRegularExpression(pattern: "https?:\\/.*", options: nil, error: nil)! But I had a problem, when user input urls with Capitalized symbols like it doesn't match it ( I tried let re = NSRegularExpression(pattern: "(h|H)(t|T)(t|T)(p|P)s?:\\/.*", options: nil, error:...

Trouble replacing middle of content with JavaScript regex?

javascript,regex
I have a text name[one][1][two][45][text] I catch the text "45" using this pattern /(.*?)rows\]\[([0-9]*)(.*)/; But how can I replace the only 45 with any other digit? Because if I use the same pattern with replace method, it replacing the entrire previous word. My code is var name = "name[one][1][two][45][text]"; var...

Remove escaping \n

regex,r
Some data: x <- c("Town\[email protected]\n\n","\[email protected]\n","\[email protected]\n\n","\[email protected]\n","[email protected]") This would work but there is word before \n gsub("\n","",x,fixed=T) This works but if there isn't \n gives NA unlist(lapply(regmatches(x,gregexpr("(?<=\n).*",x,perl=TRUE)), function(x) x[1])) EDIT: Desired result: rep("[email protected]",5) ...

PHP Regular Expressions Counting starting consonants in a string

php,regex
I need to find out how many starting consonants a word has. The number is used later in the program. The code below does work, I am wondering if it is possible to do this with a regular expression. $mystring ="SomeStringExample"; $mystring2 =("bcdfghjklmnpqrstvwxyzABCDFGHJKLMNPQRSTWVXYZ"); $var = strspn($mystring, $mystring2); Using a regular...

Regex to remove .csv in r

regex,r,stringr
this is going to be silly. I have a string like: word <- "dirtyboards.csv" I want to remove the csv part and get "dirtyboards". I am trying: require(stringr) str_extract(word, ".*[^.csv]") I get in return: "dirtyboard" . The "s" before the ".csv" goes missing. I know I can do , gsub(".csv",...

Wondering if it would be possible using regex

javascript,regex
Consider the following example <pre> { "cccccc": {}, "aaaaaa": { "xxxxxxxx": true }, "bbbbbbb": { "yyyyy": true, "zzzzzzzz": true } } </pre> I can select x y and z and assign an action function to them re = /"(.*?)(": (true|false))/g hl = '"<span style="color:blue;" onclick="action(\'aaaaaa\',\'$1\')">$1</span>$2'; s = s.replace(re, hl) But...

sed and PHP tags

regex,linux,sed
I have a problem using SED. I have a php file whit this structure in the very first line: <?php echo 'first' ?><?php echo 'second' ?><?php echo 'third';?> I'm trying to remove the first two statements and have as a result: <?php echo 'third';?> I've tried this code: sed -i...

Capturing group recursively inside non-capturing group?

.net,regex
So I've got the following input: 1,6-10,10000,2,10-11 And the following regex: ^\d+(?:,(\d+|\d+-\d+))*$ in the .NET Regex I want to match each of the groups between the commas but I also want the capturing groups to end up like the following: Group 1: 1 Group 2: 6-10 Group 3: 10000 Group...

.split and regular expression in Ruby

ruby,regex
I want to split my string by (',') but ignore ',' if they are inside quotes. For example " 2,2,4,'hello', 'world', 'hi, there' " I want to split it so 'hi, there' will not be split into two different array elements in ruby. How can I do that? Probably use...

javascript replace dot (not period) character

javascript,regex,replace
I have some text being rendered that has an inline list with the bullet points notated by the "•" character, all on one line of text. It's ugly, but I don't want to change the source data. So I thought I'd just do a quick javascript replace to insert breaks...

Replace long integers in raw json with strings

c#,regex,json
I'm looking for a way to wrap all integers over 17 digits long in a json-formatted string in quotes (essentially making them strings when deserialized). Someone facing the same issue in Javascript posted here Convert all the integer value to string in JSON I suspect there is a way to...

Matching string inside file and returning result

regex,string,bash,shell,grep
I've got a few peculiar issues with trying to search for a string inside of a .db file. The way I tried was by using grep, which does apparently find the string(s), although this is the output: $ grep "ext" *.db Binary file enormous.db matches There are a couple problems...

Does there exist an algorithm for iterating through all strings that conform to a particular regex?

c#,regex,algorithm
I'm making a script to try and hack into an account whose login password is at least 8 characters long and includes at least 1 number, 1 special character and 1 capital letter. I will use brute force. Is there a compact, elegant and efficient way to iterate through every...

Python: isolating re.search results

python,regex,csv
So I have this code (probably super inefficient, but that's another story) that is pulling urls from html code of a blog. I have the html in a .csv, which I am putting into python, then running the regex to get the urls. Here is the code: import csv, re...

Warning: preg_match_all(): Unknown modifier '\' [duplicate]

php,regex,warnings
This question already has an answer here: PHP - preg_match and “Unknown modifier” error 3 answers I know there are tons of duplicate question like this. But I am stuck here. Can anyone help me out? Here's the code: <?php function count_images($string){ preg_match_all('/[^/\s]+/\S+\.(jpg|png|gif)/', $string, $results); return count($results[1]); } ?>...

Regex to check if string is alphanumeric separated by commas or a single alphanumeric string

regex,vb.net
I have the following right now which works fine if the string is alphanumeric and separated by commas, but it doesn't work if I only have a single string. "^([a-zA-Z0-9]+,)+[a-zA-Z0-9]+$" Works for something like "1A,1B,1C", doesn't work on "1A" Sorry, I don't know much about regex and I only got...