Menu
  • HOME
  • TAGS

BeautifulSoup: Parsing bad Wordpress HTML

python,html,regex,wordpress,beautifulsoup

At least, you can rely on the tag names and text, navigating the DOM tree horizontally - going sideways. These are all strong, p and span (with id attribute set) tags you are showing. For example, you can get the strong text and get the following sibling: >>> from bs4...

Patterns (preferably java) find floor space in sq ft

java,regex,pattern-matching

I would try with: Pattern regex = Pattern.compile("(?<= )\\d(\\d*[,\\.]?\\d+)*(?=[ .]?sq)"); where: (?<= ) - there is space before \d - starts with digit (\d*[,\.]?\d+)* - next is digit or digits, there could be comma or point with more digits - and it can repeats like in 100,000,000 (?=[ .]?sq) -...

Python regex sub named captured

python,regex

This matches and captures the empty string, followed by zero or more characters which are not captured: (?P<err>).* You want to move the .* inside the parentheses: (?P<err>.*) ...

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

javascript,regex,currency

It’s quite trivial: RegEx string.match(/\$((?:\d|\,)*\.?\d+)/g) || [] That || [] is for no matches: it gives an empty array rather than null. Matches $99 $.99 $9.99 $9,999 $9,999.99 Explanation / # Start RegEx \$ # $ (dollar sign) ( # Capturing group (this is what you’re looking for) (?: #...

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

php,regex,warnings

Use a different set of delimiters for the regex. For example, you can write preg_match_all('~[^/\s]+/\S+\.(jpg|png|gif)~', $string, $results ...

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

c#,regex,string

As you mentioned you need to capture and replace the max value, I will take into account only that non-capturing group. The special character \s+ is used to indicate one or more white spaces. Regex reg = new Regex("(Movement\s+display_name=\"Movement\"\s+type=\".*\" .*min=\".*\"\s+max=\").*(\")"); Now you can replace the not captured group, I mean...

Regex that allow void fractional part of number

c#,regex

Just get the dot outside of the captruing group and then make it as optional. @"[+-]?\d+\.?\d*" Use anchors if necessary. @"^[+-]?\d+\.?\d*$" ...

JS regex for match sentence

javascript,regex

Try following this var str='this is a pen. i am a boy'; var res= str.split(/[\.\!]+\s*|\n+\s*/); //this code return a array of sentense. alert(res); console.log(res); ...

Coloring Text in JTable Cell

java,regex,swing,jtable,tablecellrenderer

There's probably a better way, but basically, what this does it sets up a series of optional groups which allows a Pattern and Matcher to break the String down into "ranges" We then use those ranges to "inject" the rules... String text = "This is a example text background and...

PHP Regular Expressions Counting starting consonants in a string

php,regex

This is one way to do it, using preg_match: $string ="SomeStringExample"; preg_match('/^[b-df-hj-np-tv-z]*/i', $string, $matches); $count = strlen($matches[0]); The regular expression matches zero or more (*) case-insensitive (/i) consonants [b-df-hj-np-tv-z] at the beginning (^) of the string and stores the matched content in the $matches array. Then it's just a matter...

format currency regular expression javascript

javascript,regex

return num = num.substring(1).replace(/,/g , " ").replace(".", ",") + " $"; Use this to English formatted num....

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

php,regex

The quotes are an issue but not the issue you are running into when you escape them. Your delimiter is terminating your regex just before the closing a which is giving you the unknown modifier error. It appears you don't have error reporting on though so you aren't seeing that....

Regular Expression Test100-200

regex

Test(?:1\d\d|200)\b You can simply use this.See demo. https://regex101.com/r/hI0qP0/26...

Matching multi-line text

php,regex

Instead of multiline flag you need single-line here. /\[FONT=(.*?)\](.*?)\[\/FONT\]/isg Single-line modifier makes dot symbol match newline characters as well - it is exactly your issue. Multiline modifier only makes beginning/end characters (^ and $) match start/end of line....

After removing bullet points using regex getting extra space between characters

javascript,regex

You are replacing even on "empty character", which is what * means at the end when there are 0 occurrences. Try to replace it with +, which means "one or more"...

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

ruby,regex

You are trying to write a python code using ruby syntax. This is not a best approach to GTD. Slashes are handled right-to-left, yielding not what you expected. As soon as one finds herself putting three or more backslashes inside the string, she should admit, she’s doing it wrong. At...

Regular expression to replace spaces between numbers with a comma

regex,sublimetext

You can use this: (?<=\d)\s+(?=\d|\-), using find and replace all in sublime text. (?<=\d) is a positive lookbehind, it checks if the previous symbol is a digit, without actually matching it. (?=\d) is a positive lookahead, same thing - checks if the following symbol is a digit, without actually matching...

Adding and Subtracting numbers from a String

java,regex,string,delimiter

Just put +, - inside a character class. sc1.useDelimiter("\\s*[-+]\\s*"); ...

javascript replace dot (not period) character

javascript,regex,replace

Try using the unicode character code, \u2022, instead: message.replace(/\u2022/, "<br />\u2022"); ...

Wondering if it would be possible using regex

javascript,regex

You could do this in a two step regex if you so desire: [^"]*"((?:[^\\"]|\\.)*)"\s*:\s*{(.*)} Your odd matches are your keys, and your even matches are your values. You'd need to run a secondary regex on your even matches to find all your values, something like: [^"]*"((?:[^\\"]|\\.)*)"\s*:\s*(?:true|false) Which should extract all...

MySQL function with parameters syntax error

mysql,regex,function

You must be getting an error on the SET @dd line. You can't set values to any variable by assigning a statement. You have to use SELECT .... INTO ... syntax to set value for a variable. There are several other errors in your code. Change them as suggested below:...

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

python,regex,parsing,beautifulsoup,python-requests

In order to match the string with a literal backlash, you need to double-escape it in a raw string, e.g.: re.search(r'@CAD_DTA\\">(.+?)@[email protected]@CAD_LBL',result.text) ^ ^ In order to get the index of the found match, you can use start([group]) of re.MatchObject IDEONE demo: import re obj = re.search(r'@CAD_DTA\\">(.+?)@[email protected]@CAD_LBL', 'Some text [email protected]_DTA\\">I WANT...

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

regex,bash,shell,ssh,sed

You can use it with ssh and heredoc like this: ssh -t -t [email protected]<<'EOF' sed 's~out_prefix=orderid ^2\\\\d\\+ updatemtnotif/~out_prefix=orderid ^2\\\\d\\+ updatemtnotif_fr/~' ~/path/to/file exit EOF PS: It is important to quote the 'EOF' as shown....

Pandas add column to df based on list of regex patterns

python,regex,pandas

You can probably use the str.count string method. A small example: In [25]: df Out[25]: Sentence bin_class 0 i wanna go to sleep. too late to take seroquel. 1 1 Adam and Juliana are leaving me for 43 days ta... 0 In [26]: df['Sentence'].str.count(pat='to') Out[26]: 0 3 1 0 Name:...

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

regex,node.js

You can try: str = 'Chapter one'; str.match(/Chapter\s{1}(\w+)/); // or str.match(/Chapter (\w+)/); // or, for: thirty three etc str.match(/Chapter\s{1}(\w+(\s{1}\w+)?)/); Will return ["Chapter one", "one"]. Pattern description: /Chapter\s{1}(\w+)/ Chapter # will match only Chapter (case sensitive) \s{1} # one space (you can also use <space>) (\w+) # letter, at least one....

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

java,regex,string,split

Could not figure out a regex solution, but here's a non-regex solution. It involves parsing numbers (not in curly braces) before each comma (unless its the last number in the string) and parsing strings (in curly braces) until the closing curly brace of the group is found. If regex solution...

Find a regex to take part of Email

php,regex

I ended up with: $regexp = '/Nachricht\s-+\s+(.*?)\s+-+\sEnde/s'; So, it saves a few matching steps and does a bit of trimming on the message. More solid regexp.. it just works. Write a test to be on the safe side. \s - matches space -+ - matches one or more - chars...

Identify that a string could be a datetime object

python,regex,algorithm,python-2.7,datetime

What about fuzzyparsers: Sample inputs: jan 12, 2003 jan 5 2004-3-5 +34 -- 34 days in the future (relative to todays date) -4 -- 4 days in the past (relative to todays date) Example usage: >>> from fuzzyparsers import parse_date >>> parse_date('jun 17 2010') # my youngest son's birthday datetime.date(2010,...

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

regex,notepad++

Try this regex: (?<=[a-zA-Z])(\n) I used parentheses to capture the newline character. https://regex101.com/r/zS9pB4/3...

lookbehind for start of string or a character

regex,python-2.7,regex-lookarounds

re.compile(ur"(?:^|(?<=[, ]))(?:next to|near|beside|opp).+?(?=,|$)", re.IGNORECASE) You can club 3 conditions using [] and |.See demo. https://regex101.com/r/vA8cB3/2#python...

regular expression in sublime text 2 to match text

regex,sublimetext2

You can make use of the multiline flag, and ^ and $ anchors that will match at the string start and string end repsectively: (?m)^.*lonfksa\.newsvine\.com.*$ Mind that you need to escape a dot in regex to make it match a literal dot. Your regex (?s)lonfksa.newsvine.com(?s) contains unescaped dots that match...

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

javascript,regex

I don't understand why it would give me two hellos back? Because the first entry in the array is the overall match for the expression, which is then followed by the content of any capture groups the expression defines. Since the expression defines one capture group, you get back...

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

regex,vb.net

^\d{1,2}[A-Z]?(?:,\d{1,2}[A-Z]?)*$ Try this.See demo. https://regex101.com/r/hI0qP0/25...

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

c#,regex,algorithm

Let's say the domain is as following String domain[] = { a, b, .., z, A, B, .. Z, 0, 1, 2, .. 9 }; Let's say the password size is 8 ArrayList allCombinations = getAllPossibleStrings2(domain,8); This is going to generate SIZE(domain) * LENGTH number of combinations, which is in...

Swing regular expression for phone number validation

java,regex

To only allow digits, comma and spaces, you need to remove (, ) and -. Here is a way to do it with Matcher.find(): Pattern pattern = Pattern.compile("^[0-9, ]+$"); ... if (!m.find()) { evt.consume(); } And to allow an empty string, replace + with *: Pattern pattern = Pattern.compile("^[0-9, ]*$");...

Find any character occur more than 4 times

sql,regex,oracle

SELECT regex_test_name FROM regex_test WHERE REGEXP_LIKE(regex_test_name, '([[:alpha:]])\1{3,9}') Inspired by dnoeth's answer, but since it catches the first character, specifying 3-9 subsequent repeats means 4-10 successive occurences in total....

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

java,regex,user-interface

How about using JFormattedTextField with MaskFormatter. JFormattedTextField formattedTextField = new JFormattedTextField("00:00:00;00"); try { MaskFormatter maskFormatter = new MaskFormatter("##:##:##;##"); maskFormatter.install(formattedTextField); } catch (ParseException e) { e.printStackTrace(); } More info at http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html Demo code: JFrame frame = new JFrame(""); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JFormattedTextField...

like and regexp_like

sql,regex,oracle,oracle11g,regexp-like

Try this one: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr(*)'); Fiddle This one also seems to work as far as I can tell: SELECT * FROM employee WHERE REGEXP_LIKE (fname, '^pr.'); Or another one that works: SELECT * FROM employee WHERE regexp_like(fname,'^pr'); ...

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

javascript,regex

This matches all given examples as well: ^\$?\d+(?:[.,:]\d+)?%?$ See it in action: RegEx101 Please comment, if adjustment / further detail is required....

how to select the first number in a link

php,regex

try this to get capture first digit: [^0-9]*(\d+) DEMO PHP Code: <?php $link = 'http://www.example/data/showall.php?quantity=&lang=eng&sura=2&ayat=21'; preg_match('/[^0-9]*(\d+)/',$link,$matches); echo $matches[1]; ?> Output: 2 ...

Regex first ends with jpg|jpeg|gif|png

python,regex

You need to change your [^/\s]+ to be lazy, rather than greedy, so it only matches up to the first .. Add a ? to the end. Note: [^\s] is every character that isn't whitespace, and / is not whitespace, so you can change it to just [^\s]. In addition,...

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

javascript,regex

why have two '\' before 's' and 't'? In regex the \ is an escape which tells regex that a special character follows. Because you are using it in a string literal you need to escape the \ with \. and what's this "[\s\t\xa0\u3000]" mean? It means to match...

Replace improper commas in CSV file

regex,r,csv

If you need the comments, you still can replace the 6th comma with a semicolon and use your previous solution: gsub("((?:[^,]*,){5}[^,]*),", "\\1;", vec1, perl=TRUE) Regex explanation: ((?:[^,]*,){5}[^,]*) - a capturing group that we will reference to as Group 1 with \\1 in the replacement pattern, matching (?:[^,]*,){5} - 5 sequences...

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

php,regex

$pattern = '! ^ # start of string \d{5} # five digits [[:alpha:]]{2} # followed by two letters - # followed by a dash \d{2} # followed by two digits $ # end of string !x'; $matches = preg_match($pattern, $input); ...

.split and regular expression in Ruby

ruby,regex

Very well. Taking inspiration from this answer, the regular expression you are looking for is: values.split(/,(?=(?:[^']*'[^']*')*[^']*$)/) This will not work if you have escaped quotes, for example (e.g. "'O\'Reilly\'s car'"). However, this looks a bit like an XY problem. If you want to parse CSV, as it seems, and if...

regex to pull in number with decimal or comma

ruby,regex

\d+(?:[,.]\d+)? Try this.This should do it for you....

Replace long integers in raw json with strings

c#,regex,json

Zero-width negative lookahead/lookbehind (https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx#grouping_constructs) is what you should be using to make sure there are no quotes at the start or end. That way you don't need to know about the exact JSON format when you do the replacement: string pattern = @"(?<![""\w])(\d{17,})(?![""\w])"; string content = Regex.Replace(content, pattern, "\"$1\""); This...

Remove escaping \n

regex,r

Use gsub. gsub("(?s)^.*?\\n|\\n.*", "", x, perl=T) ...

Regex to match ASCII Table character with decimal value

regex,decimal,ascii

You can match ASCII number codes by using \x to match escaped hexadecimal codes, e.g: \x02 should match STX...

Python match whole file name, not just extension

python,regex,nsregularexpression

You're not capturing the whole filename in the group. You can also use noncapturing groups with (?:...). .*\.(rom|[0-9]{3})+ # from this (.*\.(?:rom|[0-9]{3})) # to this ...

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

python,regex,string,loops,twitter

Store slangNames and riskNames as sets, split the strings and check if any of the words appear in both sets slangNames = set(["Vikes", "Demmies", "D", "MS", "Contin"]) riskNames = set(["enough", "pop", "final", "stress", "trade"]) d = {1: "Vikes is not enough for me", 2:"Demmies is okay", 3:"pop a D"} for...

How is the order of a re.search determined?

python,regex

The search order is left to right on the searched string; then left to right on the pattern for the same initial position in the searched string. Thus, if you are looking for r"b|c" in "dcba", "c" is found first, since it closest to the start of "dcba" than "b"....

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

javascript,regex,escaping

There's a bug in your code. As a string is immutable in JavaScript, replace doesn't change it but returns a new one. You do the replacement but you doesn't take the returned value Change val.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); to val = val.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); Demonstration...

Is there a database that can store regex as values?

regex

Prologue: Don't downvote if you don't understand the answer. At least leave a comment stating what you object. Oracle database can do that. Example query: WHERE REGEXP_LIKE(first_name, '^Ste(v|ph)en$') You want to select an regexp from a column, See SQL Fiddle example below for an example. SQL Fiddle Choose Oracle database....

Htaccess rewrite URL with virtual directory and 2 variables

regex,apache,.htaccess,url,rewriting

ok , I assume you want to change the URI from http://www.example.com/result.php?team=arsenal&player=ospina to http://www.example/subdirectory/arsenal/ospina.html so this is the .htaccess that will do that for you RewriteEngine on RewriteCond %{QUERY_STRING} ^team=(.*)\&player=(.*)$ RewriteRule ^(.*)$ http://www.example.com/subdirectory/%1/%2.html [R=301] you can test it with htaccess tester here http://htaccess.madewithlove.be/ and some useful links for documentation and...

jQuery / Regex: How to compare string against several substrings

jquery,regex,string,substring,substr

You could convert this to a slightly more maintainable format, without getting into regular expressions. This is one way to use an array to accomplish your goal: // Super-quick one-liner: var str = '2042038423408'; var matchCount = $.grep(['12', '23', '34', '45', '56', '67', '78', '89', '90', '01'], function(num, i) {...

Negate a specific group in regular expressions

regex,vb6

You can use the regex in a negative look-ahead and then add a \w shorthand class to match alphanumeric symbols, or [a-zA-Z] with \b word boundaries: (?![0-9-+*/()x]|abs|pow|ln|pi|e|a?(?:sin|cos|tan)h?)\b[a-zA-Z]+\b See regex demo Since we are only allowing letters with [a-zA-Z], we can reduce this further to (?!x|abs|pow|ln|pi|e|a?(?:sin|cos|tan)h?)\b[a-zA-Z]+\b See another demo...

Get number from string

regex

Use \d+ to match one or more digits. \b(?:http:\/\/)?(?:www\.)?example\.com\/g\/(\d+)\/\w put http:// and www. inside a capturing or non-caturing group and then make it as optional by adding ? quantifier next to that group. For both http and https, it would be (?:https?:\/\/)? DEMO...

Reg ex matching a word

regex

You could use a negative lookahead which will exclude those having _FX following the initial alpha string ^ABD_DEF_GHIJ(?!_FX)(?:_\d{8})?$ see example here...

take words out of string with Reg

regex

For anything between # and >: '(?<=#)[^#>]*(?=>)' This will match everything (excluding # and >) inside #> and the result won't include the # and > at starting and ending....

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

python,regex,string,split

You can use python's built-in csv module to do this. j = next(csv.reader([string])); Now j is each item delimited by a , and will include commas if the value is wrapped in ". See j[2]....

Pharo punctuation marks [duplicate]

regex,pharo,punctuation

What you're looking for is called a character class. A character class is a group of characters that you're saying can be matched at that position in the string. To make a character class you enclose your list of matchable characters in square brackets, like this: [.,:;!?] This will match...

Regex result capturing case

c#,regex

This might work ()(?:((?:a|b))\.(\w+)|(c)())() It matches: DEMO...

RegExp to check if file is image

javascript,regex

Put dot and / inside a character class so that it would match .png or /png strings. var imageReg = /[\/.](gif|jpg|jpeg|tiff|png)$/i; Your regex would return true if there is a dot exists before png but here there exists a forward slash , so it fails....

String#scan not capturing all occurences

ruby,regex

The reason is that after finding the first result, the regex engine continues its walk at the position after this first result. So the zero at the end of the first result can't be reuse for an other result. The way to get overlapping results is to put your pattern...

Regex with whitespaces and preceding zeros

regex,sas

You can use this simplified regex: /^[\s0]*11\s*$/ ...

How to use regex to search in a string

python,regex

Some notes about your original regex: a lookahead only makes sense at the end of the string; you were probably looking for a non-capturing group, e.g. T(?:P-) instead of T(?=P-), but you don't even need those if they appear exactly once (i.e. if there's no need to put a *,...

Regular expression for class using Beautifulsoup

python,html,regex,beautifulsoup,html-parsing

Yes, you can pass a regular expression pattern too: soup.find('div', {"class": re.compile("^divnew")}) Or, a function, checking that a class name starts with divnew: soup.find('div', {"class": lambda x: x and x.startswith("divnew"))}) Or, with a CSS selector: soup.select("div[class^=divnew]") ...

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

c#,.net,regex,string,replace

To remove all the dots present inside the square brackets. Regex.Replace(str, @"\.(?=[^\[\]]*\])", ""); DEMO To remove dot or ?. Regex.Replace(str, @"[.?](?=[^\[\]]*\])", ""); ...

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

You can simply do x="a85b080040010000" print re.sub(r"(.{2})",r"\1 ",x) or x="a85b080040010000" print " ".join([i for i in re.split(r"(.{2})",x) if i]) ...

How to get negative lookahead in regex to accept more words

regex,splunk

You may try this, - ((?:(?!\((?:not|yes)\)).)*)(?=\s|$) DEMO or - (.*?)(?=\s+\((?:not|yes)\)|$) This would capture all the chars until a space(yes) or space(no) or end of the line is reached. DEMO...

regex - Match filename with or without extension

regex,logstash-grok

This is about as simple as I can get it: \b\w+\.?\w* See demo...

Regular Expression for whole world

regex,c#-4.0,vb6

You can use: Public\s+Const\s+g(?<Name>[a-zA-Z][a-zA-Z0-9]*)\s+=\s+(?<Value>False|True) demo ...

Trouble replacing middle of content with JavaScript regex?

javascript,regex

But how can I replace the only 45 with any other digit? You can use the replace function with matching groups : For example — Here I replace the 45 with 7 : "name[one][1][two][45][text]".replace(/(.*?)(two\]\[)([0-9]*)(.*)/,function (a,b,c,d,e){ // replace 7 with what you want return b+c+'7'+e; }) Result : "name[one][3][two][7][text]" Notice...

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

python,regex,string,list,python-2.7

With such a small range you could just iterate the move_order and check if each element exists in the allowed moves def start(): move_order=[c for c in raw_input("Enter your moves: ")] moves = ['A','D','S','C','H'] for c in move_order: if c not in moves: print "That's not a proper move!" return...

Capturing group recursively inside non-capturing group?

.net,regex

The .net regex implementation gives the possibility to store the substrings of a repeated capture group. So with this pattern that describes the whole string: \A(?:(\d+(?:-\d+)?)(?:,|\z))+\z (where \A and \z stand for the start and the end of the string) you obtain all the values in capture group 1 with...

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

python,regex

The second repl parameter to re.sub can be an arbitrary function that takes a single match object and returns a string to replace it. In your case: >>> import re >>> repl = [2.888, 4.033] >>> re.sub( r'\d\.\d+', # note raw string to avoid issues with backslashes lambda match: str(repl.pop(0)),...

Remove plus sign from url using .htaccess

php,regex,apache,.htaccess,mod-rewrite

You can add a new rule for +/- conversion: Options -MultiViews RewriteEngine On RewriteBase /indianrealitybytes/ RewriteCond %{THE_REQUEST} /search_advance\.php\?keywords=([^&]+)&f=([^\s&]+) [NC] RewriteRule ^ search/%1/%2? [R=301,L] RewriteRule ^([^+]*)\+(.*)$ $1-$2 [R=302,NE,L] RewriteRule ^search/([^/]+)/([^/]+)/?$ search_advance.php?keywords=$1&f=$2 [QSA,L,NC] ...

Python regular expression, matching the last word

python,regex,list

Use the alternation with $: import re mystr = 'HelloWorldToYou' pat = re.compile(r'([A-Z][a-z]*)') # or your version with `.*?`: pat = re.compile(r'([A-Z].*?)(?=[A-Z]+|$)') print pat.findall(mystr) See IDEONE demo Output: ['Hello', 'World', 'To', 'You'] Regex explanation: ([A-Z][a-z]*) - A capturing group that matches [A-Z] a capital English letter followed by [a-z]* -...

Regex to remove .csv in r

regex,r,stringr

Try library(stringr) str_extract(word, '.*(?=\\.csv)') #[1] "dirtyboards" Another option which works for the example provided (and not very specific) str_extract(word, '^[^.]+') #[1] "dirtyboards" Update Including 'foo.csv.csv', word1 <- c("dirtyboards.csv" , "boardcsv.csv", "foo.csv.csv") str_extract(word1, '.*(?=\\.csv$)') #[1] "dirtyboards" "boardcsv" "foo.csv" ...

Python: isolating re.search results

python,regex,csv

The problem here is that re.search returns a match object not the match string and you need to use group attribute to access your desire result. If you wants all the captured groups you can use groups attribute and for a special group you can pass the number of expected...

sed and PHP tags

regex,linux,sed

.* is greedy: it matches all possible characters. This way, even sed 's/<?php.*//' file will also delete all the content in your file. To prevent this greediness of .*, say "everything but a ?" -> [^?]*: sed 's/<?php[^?]*?><?php[^?]*?>//' file Test $ cat a <?php echo 'first' ?><?php echo 'second' ?><?php...

Finding embeded xpaths in a String

java,regex

Use {} instead of () because {} are not used in XPath expressions and therefore you will not have confusions.

Regex not working in HTML5 pattern

regex,html5

The pattern attribute has to match the entire string. Assertions check for a match, but do not count towards the total match length. Changing the second assertion to \w+ will make the pattern match the entire string. You can also skip the implied ^, leaving you with just: <input pattern="(?!34)\w+"...

PHP preg_match - regular expression

php,regex,preg-match

Using preg_match_all(), something like this probably works http://www.phpliveregex.com/p/bz0 # '/(?<!\S)(?i:[a-z\d]{4}|[a-z\d]{12})(?!\S)/' (?<! \S ) # whitespace boundary (?i: # case insensitive cluster group [a-z\d]{4} # 4 alnum | # or [a-z\d]{12} # 12 alnum ) (?! \S ) # whitespace boundary ...

Matching string inside file and returning result

regex,string,bash,shell,grep

Using sqlite3 from bash on OS X seems fairly straightforward (I'm no expert at this, by the way). You will need to find out which table you need. You can do this with an interactive session. I'll show you with the database you suggested: /Users/fredbloggs> sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db SQLite version...

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

java,regex,split

First you have unnecessary escaping inside your character class. Your regex is same as: String pattern = "[(?=)]"; Now, you are getting an empty result because ( is the very first character in the string and split at 0th position will indeed cause an empty string. To avoid that result...

Regex in Perl Uninitialized $1

regex,perl

$1 is the value captured by the first capture (()), but you have no captures in your pattern. Fix: /(?<=File `..\/)(.*)(?=')/ Simplified: m{File `../(.*)'} More robust: m{File `../([^']*)'} ...

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

php,regex

You can make use of a Unicode category \p{Zs}: Zs    Space separator $string = preg_replace('~\p{Zs}~u', ' ', $string); The \p{Zs} Unicode category class will match these space-like symbols: Character Name U+0020 SPACE U+00A0 NO-BREAK SPACE U+1680 OGHAM SPACE MARK U+2000 EN QUAD U+2001 EM QUAD U+2002 EN SPACE U+2003 EM SPACE...

Regex pass dynamic values with boundry

c#,regex,string,boundary

Your first regular expression has a black slash followed by the letter b because of that @. The second one has the character that represents backspace. Just put an @ in front string bound = @"\b"; ...

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

java,regex

Use a negative lookahead assertion. string.replaceAll("test(?![^<>]*>)", "tested") Explanation: test - Matches the string test only if it's not followed by Any char but not of < or >, zero or more times. Further followed by > char. So this matches all the test except the one present inside <> ...

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

regex

Find what: ^(.{30}) Replace with: \1\n ...

Regular expression to get url in string swift

ios,regex,swift

You turn off case sensitivity using an i inline flag in regex: (?i)https?:\\/.* See Foundation Framework Reference for more information on available regex features. (?ismwx-ismwx) Flag settings. Change the flag settings. Changes apply to the portion of the pattern following the setting. For example, (?i) changes to a case insensitive...

How to define a Regex in StandardTokenParsers to identify path?

regex,scala,parsing,lexical-analysis

In a double quoted string backslash is an escape character. If you mean to use the literal backslash in a double quotes string you must escape it, thus "\d" should be "\\d". Furthermore you do not need to escape the regex dot within a character class, since dot has no...

Validate part of mail suffix

c#,regex

You can use this regex to test. It will ensure that after the @ there is .xx. but may also match the string @.xx.* .*@[^.]*[.]xx[.] Or this one to ensure that there is at least one character before and after the @. [email protected][^.]+[.]xx[.] ...