regex

Scala regex pattern match of ip address

守給你的承諾、 提交于 2021-02-16 15:09:51
问题 I can't understand why this code returns false: val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r "ttt20.30.4.140ttt" match{ case reg(one, two, three, four) => if (host == one + "." + two + "." + three + "." + four) true else false case _ => false } and only if I change it to: val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r "20.30.4.140" match{ case reg(one, two, three, four) => if (host == one + "." + two + "." + three + "." + four) true else false case _ =>

Regular expression with calculated field in Google Data Studio

落花浮王杯 提交于 2021-02-16 15:09:05
问题 I have the following calculated field but It doesn't work : sum(CASE WHEN REGEXP_MATCH(url, 'foo') THEN 1 ELSE 0 END) My goal is to sum all the url containing the word 'foo'. Does it make sense ? Where is my mistake ? Thanks 回答1: You need to use .*foo.* since REGEXP_MATCH requires a full string match: REGEXP_MATCH attempts to match the entire string contained in field_expression . Use sum(CASE WHEN REGEXP_MATCH(url, '.*foo.*') THEN 1 ELSE 0 END) ^^ ^^ 来源: https://stackoverflow.com/questions

Regular expression with calculated field in Google Data Studio

人盡茶涼 提交于 2021-02-16 15:06:59
问题 I have the following calculated field but It doesn't work : sum(CASE WHEN REGEXP_MATCH(url, 'foo') THEN 1 ELSE 0 END) My goal is to sum all the url containing the word 'foo'. Does it make sense ? Where is my mistake ? Thanks 回答1: You need to use .*foo.* since REGEXP_MATCH requires a full string match: REGEXP_MATCH attempts to match the entire string contained in field_expression . Use sum(CASE WHEN REGEXP_MATCH(url, '.*foo.*') THEN 1 ELSE 0 END) ^^ ^^ 来源: https://stackoverflow.com/questions

RegEx to match string between two strings in Powershell

吃可爱长大的小学妹 提交于 2021-02-16 15:02:07
问题 Here is my sample data: Option failonnomatch on Option batch on Option confirm Off open sftp://username:password@host.name.net:22 hostkey="ssh-rsa 1024 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" get File*.txt \local\path\Client\File.txt mv File*.txt /remote/archive/ close exit I would like to create a powershell script to extract pieces of information out of this text file. List of items I need: Username Password Host Port ssh key File Name Local Path Remote Path I'm hoping that if I

Regex - Identify Fractions

寵の児 提交于 2021-02-16 14:54:09
问题 I need to identify a fraction from a form field in a recipe database using a Regex. Ingredients will be entered in a two part form fields. Field one is the amount, Field two is the ingredient. I then need to break field one into its fractional components to input into the database. Possible entries include: 1, 1/2, 1 1/2, and any of the previous with words attached such as 1 cup, or 1/2 tbsp. the hardest I foresee would be: [2 28 oz. cans] where 2 is the number, and 28 oz. cans would be the

I need to extract Data from a single line of json-data which is inbetween two variables (Powershell)

大城市里の小女人 提交于 2021-02-16 14:49:27
问题 I need to extract Data from a single line of json-data which is inbetween two variables (Powershell) my Variables: in front of Data: DeviceAddresses":[{"Id": after Data: ," I tried this, but there needs to be some error because of all the special characters I'm using: $devicepattern = {DeviceAddresses":[{"Id":{.*?},"} #$deviceid = [regex]::match($changeduserdata, $devicepattern).Groups[1].Value #$deviceid 回答1: As you've found, some character literals can't be used as-is in a regex pattern

Pandas string extract all the matches

旧城冷巷雨未停 提交于 2021-02-16 14:39:25
问题 I am learning regex operation in pandas series string method. I was able to extract the first number from the string, but my regex is not matching the second number. How to capture both the numbers? Note that second row, the second element is NAN here. CODE: import pandas as pd df = pd.DataFrame({'a': ["number 1.23 has 1.2 ", "number 12.2 has 12 "]}) pat = r""".+\s+ (\d+\.\d+) .+ ((?:\d+\.\d+)?) .+""" df['a'].str.extract(pat,flags=re.X,expand=True) Gives: 0 1 1.23 12.2 Expected: 0 1 1.23 1.2

Replace whitespace but only between limits php

无人久伴 提交于 2021-02-16 14:37:28
问题 I want to replace whitespaces with another string using PHP. I do it as follows : $string = 'whatever text including some $text between delimiters$ and...'; $string_replaced = preg_replace('/\s\s+/', '\:', $string); But it replaces all the spaces in the string, which is very logic. I only want the regex to apply between the $ delimiters. In the official preg_replace() docs, I do not find anything that might help. So I guess I am missing some PHP feature that will allow this. 回答1: You may use

Regular expression for alpahbet,underscore,hyphen,apostrophe only

杀马特。学长 韩版系。学妹 提交于 2021-02-16 14:19:48
问题 I want a regular expression that accept only alphabets,hyphen,apostrophe,underscore. I tried /^[ A-Za-z-_']*$/ but its not working. Please help. 回答1: Your regex is wrong. Try this: /^[0-9A-Za-z_@'-]+$/ OR /^[\w@'-]+$/ Hyphen needs to be at first or last position inside a character class to avoid escaping. Also if empty string isn't allowed then use + (1 or more) instead of * (0 or more) Explanation: ^ assert position at start of the string [\w@'-]+ match a single character present in the list

Splitting on group of capital letters in python

半城伤御伤魂 提交于 2021-02-16 14:10:54
问题 I'm trying to tokenize a number of strings using a capital letter as a delimited. I have landed on the following code: token = ([a for a in re.split(r'([A-Z][a-z]*)', "ABCowDog") if a]) print token And I get this, as expected, in return: ['A', 'B', 'Cow', 'Dog'] Now, this is just an example string to make life easier, but in my case I want to go through this list and find individual characters (easy enough with checking len()) and putting the individual letters together, provided they meet a