regexp-replace

Having issue with back reference in TCL

微笑、不失礼 提交于 2019-12-08 09:48:16
问题 I have the following code: set a "10.20.30.40" regsub -all {.([0-9]+).([0-9]+).} $a {\2 \1} b I am trying to grep 2nd and 3rd octet of the IP address. Expected output: 20 30 Actual output: 20 04 0 What is my mistake here? 回答1: You need to set the variables for the match and captured groups, then you can access them. Here is an example: set a "10.20.30.40" set rest [regexp {[0-9]+\.([0-9]+)\.([0-9]+)\.[0-9]+} $a match submatch1 submatch2] puts $submatch1 puts $submatch2 Output of the demo 20

REGEXP_REPLACE capturing groups

久未见 提交于 2019-12-05 16:02:25
问题 I was wondering if someone could help me understand how to use Hive's regexp_replace function to capture groups in the regex and use those groups in the replacement string. I have an example problem I'm working through below that involves date-munging. In this example, my goal is to take a string date that is not compatible with SimpleDateFormat parsing and make a small adjustment to get it to be compatible. The date string (shown below) needs "GMT" prepended to the offset sign (+/-) in the

Comparing comma separated values from two columns of two different tables

扶醉桌前 提交于 2019-11-29 23:44:08
问题 I want to compare the values of two columns (diff table) having comma separated values of two different Oracle tables. I want to find rows that match with all values ( NAME1 all values should match with NAME2 values). Note: The comma separated values are in different order. Example: T1: ID_T1 NAME1 =================================== 1 ASCORBIC ACID, PARACETAMOL, POTASSIUM HYDROGEN CARBONATE 2 SODIUM HYDROGEN CARBONATE, SODIUM CARBONATE ANHYDROUS, CITRIC ACID 3 CAFFEINE, PARACETAMOL PH. EUR.

how to use Regexp_replace in spark

China☆狼群 提交于 2019-11-29 10:10:05
I am pretty new to spark and would like to perform an operation on a column of a dataframe so as to replace all the , in the column with . Assume there is a dataframe x and column x4 x4 1,3435 1,6566 -0,34435 I want the output to be as x4 1.3435 1.6566 -0.34435 The code I am using is import org.apache.spark.sql.Column def replace = regexp_replace((x.x4,1,6566:String,1.6566:String)x.x4) But I get the following error import org.apache.spark.sql.Column <console>:1: error: ')' expected but '.' found. def replace = regexp_replace((train_df.x37,0,160430299:String,0.160430299:String)train_df.x37) Any

How to remove duplicates from comma separated list by regexp_replace in Oracle?

五迷三道 提交于 2019-11-28 13:12:01
I have POW,POW,POWPRO,PRO,PRO,PROUTL,TNEUTL,TNEUTL,UTL,UTLTNE,UTL,UTLTNE I want POW,POWPRO,PRO,PROUTL,TNEUTL,UTL,UTLTNE I tried select regexp_replace('POW,POW,POWPRO,PRO,PRO,PROUTL,TNEUTL,TNEUTL,UTL,UTLTNE,UTL,UTLTNE','([^,]+)(,\1)+','\1') from dual And I get the output POWPROUTL,TNEUTL,UTLTNE,UTLTNE But i want the output to be POW,POWPRO,PRO,PROUTL,TNEUTL,UTL,UTLTNE Please help. Two solutions that use only SQL and a third solution that uses a small/simple PL/SQL function which makes for a very short final SQL query. Oracle Setup : CREATE TABLE data ( value ) AS SELECT 'POW,POW,POWPRO,PRO,PRO

how to use Regexp_replace in spark

别等时光非礼了梦想. 提交于 2019-11-28 03:15:35
问题 I am pretty new to spark and would like to perform an operation on a column of a dataframe so as to replace all the , in the column with . Assume there is a dataframe x and column x4 x4 1,3435 1,6566 -0,34435 I want the output to be as x4 1.3435 1.6566 -0.34435 The code I am using is import org.apache.spark.sql.Column def replace = regexp_replace((x.x4,1,6566:String,1.6566:String)x.x4) But I get the following error import org.apache.spark.sql.Column <console>:1: error: ')' expected but '.'

How to remove duplicates from comma separated list by regexp_replace in Oracle?

荒凉一梦 提交于 2019-11-27 07:39:55
问题 I have POW,POW,POWPRO,PRO,PRO,PROUTL,TNEUTL,TNEUTL,UTL,UTLTNE,UTL,UTLTNE I want POW,POWPRO,PRO,PROUTL,TNEUTL,UTL,UTLTNE I tried select regexp_replace('POW,POW,POWPRO,PRO,PRO,PROUTL,TNEUTL,TNEUTL,UTL,UTLTNE,UTL,UTLTNE','([^,]+)(,\1)+','\1') from dual And I get the output POWPROUTL,TNEUTL,UTLTNE,UTLTNE But i want the output to be POW,POWPRO,PRO,PROUTL,TNEUTL,UTL,UTLTNE Please help. 回答1: Two solutions that use only SQL and a third solution that uses a small/simple PL/SQL function which makes for

Laravel preg_match(): No ending delimiter '/' found

左心房为你撑大大i 提交于 2019-11-26 22:48:22
Im working on Laravel 4.2. Im trying to use Validator to validate a name field with regex, here is my rule below: public static $rules_save = [ 'class_subjects' => 'required|regex:/[0-9]([0-9]|-(?!-))+/' ]; But as soon as I call the rule to be validated an error is thrown, see below: preg_match(): No ending delimiter '/' found Since your regex has a pipe in it, you have to use an array: public static $rules_save = [ 'class_subjects' => ['required', 'regex:/[0-9]([0-9]|-(?!-))+/'], ]; From the docs : When using the regex pattern, it may be necessary to specify rules in an array instead of using