I have thousands of line having different time value like to_timestamp('14/03/18 07:46:33,573000000','DD/MM/RR HH24:MI:SSXFF'), and I want to replace all this with a single string say GETDATE().
for example i have following entries in my file,
to_timestamp('14/03/18 07:46:33,573000000','DD/MM/RR HH24:MI:SSXFF')
to_timestamp('14/03/18 08:45:34,342000000','DD/MM/RR HH24:MI:SSXFF')
to_timestamp('04/01/18 18:15:08,119000000','DD/MM/RR HH24:MI:SSXFF')
Now I would like to replace all of them with GETDATE() string like below
GETDATE()
GETDATE()
GETDATE()
How I can achive this with Notepas++ with regular expression ? or is there any other way to achieve this?
If you don't have any other function like this you can simply use regex (to_timestamp\(.*?\))
If it wants to be specific then use,
(to_timestamp\('\d+\/\d+\/\d+\s\d+:\d+:\d+,\d+','DD\/MM\/RR\sHH24:MI:SSXFF'\)) and replace with GETDATE\(\)
Regex
Use the regex to_timestamp\(.*\)
Related
I'm a total noob with regexp. All I want to do is to remove the single and double quotes from a string in BigQuery. I can remove the single and double quotes at the beginning of the string, but not the end:
SELECT regexp_extract(foo, r'\"new_foo\":\"(.*?)\"') AS new_foo
FROM [mybq:Schema.table]
All I get is Null but without regexp_extract I have expected results. Help is appreciated.
Try something like below
SELECT REGEXP_REPLACE(foo, r'([\'\"])', '') AS new_foo
FROM [mybq:Schema.table]
Your regex expression should be like /["']/g
And your are using different method to get the expected result. Try REGEXP_REPLACE('orig_str', 'reg_exp', 'replace_str')
Something like this:
SELECT REGEXP_REPLACE(word, /["']/g, '')AS new_foo
FROM [mybq:Schema.table]
select replace(word,'"','') as word
Basically, I have list of URLs that look like this:
http://auctionnetwork.com.my/auctiondate_img.php?id=244003
and I want to extract auctiondate_244003, how would I do that with regex?
I want the output to be "auctiondate_244003".
You didn't define exactly what you are looking for.
How about something like: \/([^\/]*)img\.php\?id=([0-9]+)?
You'll have to concatenate the 1st and second match groups to get what you need
See https://regex101.com/r/dD2hW6/1
i want to use Regex in div at HTML in order to replace a certain string, this string is like :
age:7Refat"student" or it will be like age:7Refat , i'm using the following command that is ok with the second pattern:
$("#order_list").append($(this).text().replace(new RegExp("age:[0-9]+","g"),''));
but what if i want to use a general command for both patterns, the something is i don't know how to deal with the first pattern as it has double quotes"" , and i can't write:
$("#order_list").append($(this).text().replace(new RegExp("age:[0-9]+"[a-z]"","g"),''));
or
$("#order_list").append($(this).text().replace(new RegExp("price:[0-9]+[\"a-z\"]","g"),''));
Either escape the quotes like you did in your third example (but I think you put them in the wrong place):
new RegExp("price:[0-9]+\"[a-z]\"","g")
or (better) use a regex literal:
/price:[0-9]+"[a-z]"/g
You may try this
$("#order_list").append($(this).text().replace(new RegExp("age:[0-9]+\"[a-z]\"","g"));
instead of this:-
$("#order_list").append($(this).text().replace(new RegExp("age:[0-9]+","g"),''));
That finally works with me :
$("#order_list").append(($(this).text().replace(new RegExp("age:[0-9]+","g"),'')).replace(new RegExp("[a-zA-Z]+","g"),'').replace(new RegExp("\"+","g"),''));
I have the following date string - "2013-02-20T17:24:33Z"
I want to write a regex to extract just the date part "2013-02-20". How do I do that? Any help will be appreciated.
Thanks,
Murtaza
You could use capture group for this.
/(\d{4}-\d{2}-\d{1,2}).*/
Using $1, you can get your desired part.
Well straightforward approach would be \d\d\d\d-\d\d-\d\d but you can also use quantifiers to make it look nicer \d{4}-\d{2}-\d{2}.
Just search for the first T and use substring. I assume you always get a well-formatted date string.
If the date string is not guaranteed to be valid, you can use any date related library to parse and validate the input (validation includes the calendar logic, which regex fails to achieve), and reformat the output.
No sample code, since you didn't mention the language.
using substring
string date = "2013-02-20T17:24:33Z";
string h = date.Substring(0, 10);
I have a table that contains a number of rows with columns containing a URL. The URL is of the form:
http://one.example1.com:9999/dotFile.com
I would like to replace all matches in that column with http://example2.com/dotFile.com while retaining everything after :9999. I have found some documentation on regexp_matches and regexp_replace, but I can't quite wrap my head around it.
To replace a fixed string, use the simple replace() function.
To replace a dynamic string, you can use regexp_replace() like this:
UPDATE
YourTable
SET
TheColumn = regexp_replace(
TheColumn, 'http://[^:\s]+:9999(\S+)', 'http://example2.com\1', 'g'
)
if you know the url, you don't have to use regex. replace() function should work for you:
replace(string text, from text, to text)
Replace all occurrences in string of substring from with substring to
example: replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef
you could try:
UPDATE yourtable SET
yourcolumn = replace(yourcolumn, 'one.example1.com:9999','example2.com')
;