regex

Php regex: remove order by from query string

老子叫甜甜 提交于 2021-02-19 08:06:12
问题 I have a php method, which should remove all occurences of an "order by" mysql statement from a mysql query string. Example 1: STRING: SELECT * FROM table ORDER BY name RESULT: SELECT * FROM table Example 2: STRING: SELECT a.* FROM (SELECT * FROM table ORDER BY name, creation_date) AS a ORDER BY a.name Result: SELECT a.* FROM (SELECT * FROM table) AS a My question now is: How to achive this. I have tried the following: if (stripos($sql, 'ORDER BY') !== false) { $sql = preg_replace('/\sORDER\

Python - regex to extract IP and Mask from snmp walk output

不羁的心 提交于 2021-02-19 07:48:22
问题 I am struggling with regex to extract IP and subnet mask info from a snmp walk output. Here is how output looks like. [<SNMPVariable value='255.255.255.0' (oid='iso.3.6.1.2.1.4.21.1.11.10.10.2.0', oid_index='', snmp_type='IPADDR')>, <SNMPVariable value='255.255.255.192' (oid='iso.3.6.1.2.1.4.21.1.11.10.0.0.0', oid_index='', snmp_type='IPADDR')>, <SNMPVariable value='255.255.255.0' (oid='iso.3.6.1.2.1.4.21.1.11.10.10.10.0', oid_index='', snmp_type='IPADDR')>, <SNMPVariable value='255.255.255

Regular expression to extract number with sign between quotes

一世执手 提交于 2021-02-19 07:43:26
问题 I'm using Unity 5.3.4 and using C#. I was wondering if it would be possible to extract with regular expressions the value in this string, I do need the sign, as now is negative but it doesn't have to be that way: string str = " "rssi": "-56", " I do know that to use regular expression in unity it would be this way: str = Regex.Replace(str, "*regular expression*", String.Empty); I was wondering what would be a proper regular expression. I've been trying some in http://www.regexr.com/ But with

Java Regex recursive match

喜欢而已 提交于 2021-02-19 07:34:07
问题 I have a string like this: IF(expr1,text1,IF(expr2,text2,IF(expr3,text3,text4))) I need to process IF(expr3,text3,text4))) so the above become IF(expr1,text1,IF(expr2,text2,new_text)) I need to keep doing this until I have IF(expr1,text1,new_text3) My pattern string "IF\\(.*?,.*?,.*?\\)" will match the whole thing. Not the IF(expr3,text3,text4))) . Java code: String val = "IF(expr1,text1,IF(expr2,text2,IF(expr3,text3,text4)))"; String regx = "IF\\(.*?,.*?,.*?\\)"; Pattern patt1 = Pattern

JavaScript Regexp to replace a value only when it follows certain characters?

我们两清 提交于 2021-02-19 07:30:23
问题 I'm trying to come up with a regular expression which will search for a string and replace with new set of characters. My string is something like this. (Product=='Partnership - CT'&&State==CT) Here I have to search for the CT value for state key and replace with 'CT' (i.e., add single quotation marks). I have used the following Regexp in JavaScript. var expressionQuery = "(Product=='Partnership - CT'&&State==CT)"; val = 'CT'; expressionQuery.replace(new RegExp(val, "g"),"\'"+val+"\'" ); But

python pandas use map with regular expressions

走远了吗. 提交于 2021-02-19 06:36:05
问题 I have a dict: dealer = { 'ESSELUNGA': 'Spesa', 'DECATHLON 00000120': 'Sport', 'LEROY MERLIN': 'Casa', 'CONAD 8429': 'Spesa', 'IKEA': 'Casa', 'F.LLI MADAFFARI': 'Spesa', 'SUPERMERCATO IL GIGANT': 'Spesa', 'NATURASI SPA': 'Spesa', 'ESSELUNGA SETTIMO MILANE': 'Spesa' } and I want to map it to a pandas df: entries.Categoria = entries.Commerciante.map(dealer) Is there a way to use regex to match map on "Commerciante" column? In this way I can rewrite dealer as this: dealer = { 'ESSELUNGA': 'Spesa

Microbenchmarking base R and three packages on string pattern substitution

妖精的绣舞 提交于 2021-02-19 06:25:44
问题 My question is whether my method and conclusion are correct. As part of my learning regular expressions, I wanted to figure out in which order to learn the various alternatives (base R and packages). I thought it might help to learn the relative speeds of the alternative functions. So, I created a string vector and called what I hope are equivalent expressions. sites <- c("http://grand.test.com/", "https://example.com/", "http://.big.time.bhfs.com/", "http://test.blogs.mvalaw.com/") vec <-

Matching emojis in C#

微笑、不失礼 提交于 2021-02-19 06:00:50
问题 I am trying to find a way to filter emojis from utf8 text files. Apparently there is a javascript regex available (https://raw.githubusercontent.com/mathiasbynens/emoji-regex/master/index.js) which can be used to match emojis. I could not translate this regex to c# dialect (looks like there are some differences i don't understand). Then I tried following simple code to match all non-word and non-space characters in my texts (to go over them manually and select emojis, then put them in a regex

Regex in Python: Separate words from numbers JUST when not in list

依然范特西╮ 提交于 2021-02-19 05:40:30
问题 I have a list containing some substitutions which I need to keep. For instance, the substitution list: ['1st','2nd','10th','100th','1st nation','xlr8','5pin','h20'] . In general, strings containing alphanumeric characters need to split numbers and letters as follows: text= re.sub(r'(?<=\d)(?=[^\d\s])|(?<=[^\d\s])(?=\d)',' ',text,0,re.IGNORECASE) The previous regex pattern is separating successfully all numbers from characters by adding space between in the following: Original Regex ABC10 DEF

Non-capturing optional URL elements in Django

非 Y 不嫁゛ 提交于 2021-02-19 05:34:56
问题 I'm using Django and would like to match the URLs domain.com/w and domain.com/words . I have a configuration line of the form: url(r'^w(ords)?$', 'app_name.views.view_words') view_words takes only one parameter ( request ), but it seems that Django captures the (ords) part of the regular expression and passes it to the view. When I remove (ords) from the regex and access domain.com/w , it works properly. The Django documentation and similar StackOverflow questions cover how to capture