2018-10-22         Irene

Regex Validation for Dialog Flow Entity name

I am trying to write regular expression for validating name that can be used as entity name.Criteria : Entity name may contain only the following: A-Z, a-z, 0-9, _ (underscore), - (dash). And it should start with a letter.This is my Python code for the same(which is not correct)import refrom random import randintentityName = 'Enity Demo-trial'if re.search(r"^[a-zA-Z][[_|a-zA-Z|0-9|-]*]+",entityName): print("Validation failed")else: print("Validation satisfied") [a-zA-Z][\w\-]* will work for you.You don't need to include all those OR operators "|" inside a character...

 regex                     2 answers                     26 view
 2018-10-22         Eli

How to use numbers as a whole in regular expressions

I have some Chinese addresses, and I want to extract strings by regular expressions.I want to get it like:"商城1栋11楼1112室 " #return <_sre.SRE_Match object; span=(7, 12), match='1112室'>My idea is to remove the format that satisfies "栋 + number + (楼|单元)". I used (栋+[0-9]*(?!楼|单元)) to do it, but it separates the numbers. As follow: >>>ms = re.finditer(re.compile("(栋+[0-9]*(?!楼|单元))|([0-9]+室)"),"商城1栋11楼1112室")The result is that:<_sre.SRE_Match object; span=(3, 5), match='栋1'><_sre.SRE_Match object; span=(7, 12), match='1112室'>How do I achieve the goal o...

 regex                     2 answers                     27 view
 2018-10-22         Leopold

Parse files in a directory that contain a match to a set of strings - pull line with match to new file

I need to parse through a directory of multiple excel files to find matches to a set of 500+ strings (that I currently have in a set). If there is a match to one of the strings in an excel file, I need to pull that row out into a new file. Please let me know if you can assist! Thank you in advance for the help!The directory is called: All_DataThe set is from a list of strings in a file (MRN_file_path) My code:MRN = set()with open(MRN_file_path) as MRN_file: for line in MRN_file: if line.strip(): MRN.add(line.strip())for root, dires, files in os.walk('pa...

 regex                     1 answers                     28 view
 2018-10-22         Myrna

how to change strings/labels in a csv file

My code is given below. I have a input_df.csv file as given below: input_df = [time:[1,2,3,4],v1=[10,20,30,40],p1=[1,2,3,4],v2=[10,20,30,40],p2=[1,2,3,4]]I want to change the title of two strings in above dataframe. That is, p1 and p2 to i1, i2. I tried following way: import re with open('input_df.csv', 'r') as f: my_csv_text = f.read()new_csv_str = re.sub('p1', 'i1', my_csv_text)new_csv_str1 = re.sub('p2', 'i2', my_csv_text)with open('modifiedInput_df.csv', 'w') as f: f.write(new_csv_str),f.write(new_csv_str1)with open('modifiedInput_df.csv', 'w') as f: f.writ...

 regex                     1 answers                     29 view
 2018-10-22         Malcolm

Byte error in regexp

So, here's the code : #!/usr/bin/pythonfrom sys import exitimport urllib.requestanswer = urllib.request.urlopen("http://monip.org").read()def debug(txt): print(txt) exit(0)def parse_answer(answer): ''' Simple function to parse request's HTML result to find the ip in it. Raise RuntimeError if no ip in result and ip else. ''' import re pattern = "^\w+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\w+$" regexp = re.compile(pattern) if regexp.match(regexp, answer): m = regexp.search(regexp, answer) ip = m.group(0) return ip el...

 regex                     2 answers                     31 view
 2018-10-22         Bradley

Cannot find suitable regex

What I'm trying to do is to pull the HTML content and find a particular string that I know existsimport urllib.requestimport reresponse = urllib.request.urlopen('http://ipchicken.com/')data = response.read()portregex = re.compile('Remote[\s]+Port: [\d]+')port = portregex.findall(str(data))print(data)print(port)Now in my case the website contains Remote Port: 50880, but I simply cannot come up with suitable regex! Can anyone find my mistake?I'm using python 3.4 on Windows You mistakenly used square brackets instead of round parentheses:portregex = re.compile(r'Remote\...

 regex                     3 answers                     33 view
 2018-10-22         Roberta

Error in regular expression and transform into float?

I´m trying to obtain a string inside a file id = re.compile('[1-90]\s[0-59].[0-99].+')if id.search(pal): print ('si') a = id.search(pal)else: print('NO')>>>a.group()'7 3.99 N, 1 13.02 W'But the original string is : 37 3.99 N, 1 13.02 WThen I´ve lost the first str '3'How can I modify the pattern in order to obtain the full stringAnother questionHaw can I use the string as a digit, ie, this is a position in Degrees and Minutes and I ´d like to transform.... into degrees.minutes gg.mmm You need to capture these one character at a time. For instance, t...

 regex                     2 answers                     38 view
 2018-10-22         Fanny

How to change case from upper to lower of a words 1st letter if the same word occures at least one time in lower case using regex only

I've created the following RegEx in Python 3 to find all lower case words in a text and back reference the first letter and the tail of that word. Example:w ord^ ^^^| |1st letter tailAfterwards I use a for loop to replace all occurrences of matches with the first group converted to uppercase and the unaltered tail with the lowercase first letter followed by the unaltered tail.str = "Some text here and some more after that. Something that should remain untouched."for match in re.finditer(r"\b([a-z])([a-z]+)\b", str): # print(match.group(1).upper...

 regex                     1 answers                     41 view
 2018-10-22         Yves

sparql regex file extension

I'm trying to develop a SPARQL Query to capture the file extension in an object of a RDF.SELECT DISTINCT*WHERE { ?s <http://URI/identifier> ?o . BIND(REPLACE(?o,".*\.(\w+)", "$1") AS ?filetype)} LIMIT 10My Regular Expression (.*\.(\w+) is getting an error though.MALFORMED QUERY: Lexical error at line 5, column 25. Encountered: "." (46), after : "\".*\\"However my expression works in my Regex 101What characters do I need to escape and how? From the error message I am guessing you are using RDF4J Console or Workbench. There is an open issue with the escaping ...

 regex                     1 answers                     68 view
 2018-10-22         Cornelia

Add parameter to String#replace

I want to remove the last character from a string if it is a pipe. I have.replace(/\|(\s+)?$/, '')I want to add a parameter delim to replace since the last character changes. I am trying:.replace(/\+delim +(\s+)?$/, '')but no luck.The code that uses this function: rangeValues[cellRow][hn[j]] = rangeValues[cellRow][hn[j]].toString() .split(frValues[i][0]) .join(frValues[i][1]).trim() .replace(/\ + delim + (\s+)?$/, ''); You want to remove a last character using regex.You want to use by changing delim in the regex.If my understanding for your question is correc...

 regex                     1 answers                     66 view
 2018-10-22         Ken

Replacing Regex expression that is not supported with Google Script

A short background of what I am trying to achieve: I have a Google Doc and A google sheet.The google doc contains text and the google sheet contains 2 columns: a word and it's translation.the function gets the body of the google doc and supposed to go over the "words" col, identify all appearances of each word in the body and replace it with its translation - but it matches only occurrences that are whole-words and exact match only.What basically I want to have would be easier to explain with an example:Let's say I have the word "pop" and it is translated to "pretty". I wan...

 regex                     1 answers                     67 view
 2018-10-22         Bevis

Big query standard vs legacy syntax

the below functions works perfectly on sql legacy, but fails on sql standard with error:"No matching signature for function REGEXP_EXTRACT for argument types: ARRAY, STRING. Supported signatures: REGEXP_EXTRACT(STRING, STRING); REGEXP_EXTRACT(BYTES, BYTES)" regexp_extract(split(something,','), r'^(.*?)\:')I've tried to replace ' with ".. no success.Any ideas? Instead of using split and regexp_extract, you could also drop into a UDF in JS that allows you to parse easily:CREATE TEMPORARY FUNCTION parse(json STRING) RETURNS ARRAY<STRING> LANGUAGE js AS """ p =...

 regex                     2 answers                     26 view
 2018-10-22         Winni

I need a regex to extract a specific character between delimiter

I need a regex to extract a specific character between delimiter, the specific character is ~ and the delimiter is ".This is some example text :~104.7866 ~"~A.SITI FATONAH "~2014/06/23and0.0 ~ 0.0 ~"ENI NURLINI ( 341676 ) ~ "~2016/05/18I want to delete the ~ between two ", so the output is~104.7866 ~"A.SITI FATONAH "~2014/06/23and0.0 ~ 0.0 ~"ENI NURLINI ( 341676 ) "~2016/05/18I'm planning to use regex_replace in sql to replace the ~ but I cant find the right regex Below example is for BigQuery Standard SQL #standardSQLWITH `project.dataset.table` AS ( SELECT '~104.78...

 regex                     2 answers                     78 view
 2018-10-22         Dominic

Bigquery Standard Dialect REGEXP_REPLACE input type

I am exploring the power of Google Biguery with the GDELT database using this tutorial however the sql dialect is in 'legacy' and I would like to use the standard dialect. In legacy dialect: SELECT theme, COUNT(*) AS countFROM ( SELECT REGEXP_REPLACE(SPLIT(V2Themes,';'), r',.*',"") themefrom [gdelt-bq:gdeltv2.gkg]where DATE>20150302000000 and DATE < 20150304000000 and V2Persons like '%Netanyahu%')group by themeORDER BY 2 DESCLIMIT 300and when I try to translate into standard dialect:SELECT theme, COUNT(*) AS countFROM ( SELECT REGEXP_REPLACE(SPLIT(V2Themes...

 regex                     1 answers                     80 view
 2018-10-22         Susanna

Money amount regex currency name after the amount

I am trying to create a regular expression that matches money amount (various currencies either in front of or after the given amount. The decimals are separated by a dot or by a comma).This is what I've got so far:\$[0-9.,]+|\£[0-9.,]+|\€[0-9.,]+However, if I put currencies in the square brackets together with the other signs, it does not work as I expect it to (it still doesn't match 20,000$, only $20,000 and I want it to match both).Can you tell me how I can modify my regex so that it also matches the amounts with the currency after the digits? Also, is the only way to i...

 regex                     1 answers                     5 view
 2018-10-22         Darcy

Apache: Block all directories except for listed ones

I want to block people from accessing every directory except for /sandbox, /WebDev and /ProjectsI tried this:<Directory ^/(?<!sandbox|Projects|WebDev)+(/.*)> Order Deny,Allow Deny from all</Directory>but it gave a 500 error. The canonical way is something like:<Directory /> Order Deny,Allow Deny from all</Directory><Directory /sandbox> Order Deny,Allow Allow from all</Directory><Directory /WebDev> Order Deny,Allow Allow from all</Directory><Directory /Projects> Order Deny,Allow Allow f...

 regex                     2 answers                     23 view

Page 1 of 406  |  Show More Pages:  Top Prev Next Last