So I am looking to simply combine the two replaces listed below. I have tried & and .
Replace( [WEBSTORE_LINK] ,"https://webstore.f-w.com","J:\2020\0200905.00 - AVC - Boone Reach\GIS\Research\Webstore")
Replace ( [Link] , "/", "")
So this is within the Link Field that I am trying to do this. So the first replace works alone however the slashes are going the wrong way. And so I just need to add another replace to fix that issue.
Related
I am converting exported SQL views as files to a different syntax using a separate specialized conversion tool. This tool can't handle certain commands and formatting so I'm using Notepad++ with RegEx to alter the files ahead of time.
So far I am getting the results that I want, but it takes three separate Find/Replace actions. I'd like to reduce these three RegEx actions down to one if possible.
Find: (.*)(CREATE VIEW.*\nGO)(.*)
Replace: \2
Find: (CREATE VIEW )(.*)(\r\nAS)
Replace: \1"\2"\3
Find: (oldschema1\.|\[oldschema1\]\.|\[|\]|TOP \(100\) PERCENT|oldschema2\.)|(^GO$)|(\A^(.*?))
Replace: (?1)(?2\;)(?3SET SCHEMA schemaname\; \n\n\1)```
I'm using Notepad++ 7.7.1 64-bit, Find/Replace with Regular Expression search mode - ". matches newline" check on.
You'll see in my code that I'm already using capture groups with alternation. I thought I could combine the first two RegEx steps as additional capture groups to Step 3 but it doesn't work out, possibly because they are nested.
I tried referencing the nested groups by incrementing the referencing number accordingly, but it doesn't work (blanks out the result).
Here is an example SQL view file. It's not a working view because I added "oldschema2" so the RegEx would have something to find for one of the replacements, but it's representative as an example here.
garbage
text
beforehand
CREATE VIEW [oldschema1].[viewname]
AS
SELECT DISTINCT
TOP (100) PERCENT oldschema1.TABLENAME.FIELD1, oldschema1.TABLENAME.FIELD2
FROM oldschema1.TABLENAME
WHERE (oldschema1.TABLENAME.FIELD3 = N'Z003') AND oldschema2.TABLENAME.FIELD2 = 1
ORDER BY oldschema1.TABLENAME.FIELD1
GO
garbage
text
after
Here is some additional details of what I'm trying to achieve with each pass.
Notepad++ RegEx Step 1 - isolate view block from CREATE VIEW to GO
Find:
(.*)(CREATE VIEW.*\nGO)(.*)
Replace:
\2
Step 2 - put quotes around view name
Find:
(CREATE VIEW )(.*)(\r\nAS)
Replace:
\1"\2"\3
Step 3 - remove/replace various texts and insert a line at the beginning of the file
Find:
(oldschema1\.|\[oldschema1\]\.|\[|\]|TOP \(100\) PERCENT|oldschema2\.)|(^GO$)|(\A^(.*?))
Replace:
(?1)(?2\;)(?3SET SCHEMA schemaname\; \n\n\1)
The expected output from the above example would be:
SET SCHEMA schemaname;
CREATE VIEW "viewname"
AS
SELECT DISTINCT
TABLENAME.FIELD1, TABLENAME.FIELD2
FROM TABLENAME
WHERE (TABLENAME.FIELD3 = N'Z003') AND TABLENAME.FIELD2 = 1
ORDER BY TABLENAME.FIELD1
;
which I achieve with the above three steps, but I'd like to do it in one Find/Replace if possible.
I'm pretty new to RegEx, and StackOverflow for that matter. Your help is greatly appreciated.
Step 1
I'm not so sure about it, but I'm guessing that maybe we would want an expression similar to:
[\s\S]*?(CREATE VIEW[\s\S]*GO\s*)[\s\S]*
to be replaced with $1, where our desired data is in this capturing group:
(CREATE VIEW[\s\S]*GO\s*)
and we can even remove \s*:
(CREATE VIEW[\s\S]*GO)
and just try:
[\s\S]*?(CREATE VIEW[\s\S]*GO)[\s\S]*
with an m flag.
In the right panel of this demo, the expression is further explained, if you might be interested.
Step 2
We can likely try:
(CREATE VIEW)(.*)
and replace with:
SET SCHEMA schemaname;\n\n$1 "viewname"
Demo
Step 3
This step would probably be done with an expression similar to:
TOP \(100\) PERCENT |oldschema1\.
being replaced with an empty string.
Demo
Step 4:
\s*GO being replaced with \n; or just ; and we might likely have the desired output, not sure though.
Demo
In Google Sheets, I'd like to replace the following text:
The ANS consists of fibers that stimulate ((1smooth muscle)), ((2cardiac muscle)), and ((3glandular cells)).
with this text below:
The ANS consists of fibers that stimulate {{c1::smooth muscle}}, {{c2::cardiac muscle}}, and {{c3::glandular cells}}.
I know if I use =REGEXREPLACE(E3, "\(\([0-9]*", "{{c::") I can get here:
The ANS consists of fibers that stimulate {{c::smooth muscle)), {{c::cardiac muscle)), and {{c::glandular cells)).
BUT I don't know how to keep the original numbers
Nvm, figured it out.
Putting parentheses around the term allows you to reference it again in your replacement string.
For example, my solution for my problem was this:
=REGEXREPLACE(E3, "\(\(([0-9]*)", "{{c$1::")
This works because putting [0-9]* in parentheses like so: ([0-9]*) allowed it to be referenced as $1 in my substitution string.
I assume that if I had another phrase enclosed in parentheses after that it would be able to be referenced with $2.
Hope this helps someone in the future.
Pass 1:
Search Pattern:(((\d)(.+)
Replacement:{{C$1::$2
Pass 2:
Search Pattern: ))
Replacment: }}
I played around with it some more and this will do it in one pass:
Search Pattern: \(\((\d)(.+?)\b\)\)
Replacements: {{C$1::$2}}
I'm currently building a simple search page in Node JS Express and Oracle.
I'd like to show the user a snippet of the matching text (first instance would do) to add a bit context of what the SQL found.
Example:
Search term: 'fish'
Results: Henry really likes going fishing, and once he caug ...
I'm not sure the best way to approach this - I could retrieve the whole block of text and do it in Node JS, but I don't really like the idea of dragging the whole text across to the app, just to get a snippet.
I've been thinking that REGEXP_SUBSTR could be way to do it... But I'm not sure whether I could use a regular expression to retrieve x amount of characters before and after the matching word.
Have I got the right idea or am I going about it in the wrong way?
Thanks
SELECT text
, REGEXP_SUBSTR(LOWER(text), LOWER('fish')) AS potential_snippet
FROM table
WHERE LOWER(text) LIKE LOWER('%fish%');
Try this:
select text
, SUBSTR( TEXT, INSTR(LOWER(TEXT),'fish', 1)-50,100 )
FROM test
WHERE INSTR(LOWER(text),'fish', 1)<>0;
Play with the position and length numbers(50 and 100 in my example) to limit the length of the string.
If you need to extract some context with the help of JavaScript, you can use limiting quantifiers in a regex:
/\b.{0,15}fish.{0,15}\b/i
See demo
Here,
\b - matches at the word boundary (so that the context contains only whole words)
.{0,15} - any characters other than a newline (replace with [\s\S] or [^] if you need to include newlines)
fish - the keyword
The /i modifier enables case-insensitive search.
If you need a dynamic regex creation, use a constructor notation:
RegExp("\\b.{0,15}" + keyword + ".{0,15}\\b", "i");
Also, if you need to find multiple matches, use g modifier alongside the i.
I have to split URIs on the second portion:
/directory/this-part/blah
The issue I'm facing is that I have 2 URIs which logically need to be one
/directory/house-&-home/blah
/directory/house-%26-home/blah
This comes back as:
house-&-home and house-%26-home
So logically I need a regex to retrieve the second portion but also remove everything between the hyphens.
I have this, so far:
/[^(/;\?)]*/([^(/;\?)]*).*
(?<=directory\/)(.+?)(?=\/)
Does this solve your issue? This returns:
house-&-home and house-%26-home
Here is a demo
If you want to get the result:
house--home
then you should use a replace method. Because I am not sure what language you are using, I will give my example in java:
String regex = (?<=directory\/)(.+?)(?=\/);
String str = "/directory/house-&-home/blah"
Pattern.compile(regex).matcher(str).replaceAll("\&", "");
This replace method allows you to replace a certain pattern ( The & symbol ) with nothing ""
Simply put, I pull the href prop of a link and need to replace it with new link when clicked. The new link needs 1 parameter from the original link (a claim link opening a new window and claiming a task for a user).
Thus far I have a working solution. What I'm wanting is for someone to maybe help me refine my RegEx a little.
For links like:
/crm/v2/claimTask?email=example#gmail.com&id=1372365392-1UsIvb-0002qr-Sz
I use:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)&/)[0].replace(/&/, '')
And get:
email=example#gmail.com
What i'd like to do is be able to remove .replace(/&/, '') and have the regex stop at the & symbol to begin with, but i'm unsure how to do this. Any ideas?
Further examples:
/crm/v2/claimTask?order=123456&id=137236456452-1UweRRwvb-00456jr-Sz
/crm/v2/claimTask?phone=6665554444&id=175655392-4WERTe4-097qt-Da
/crm/v2/claimTask?num=6665554444&id=1372234392-9sfaWa-12374ip-eW
/crm/v2/claimTask?email=email#test.net&id=133453465392-k0wS24S-36735qr-rt
Using:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)&/)
Would yield:
order=123456&
phone=6665554444&
num=6665554444&
email=email#test.net&
Try this:
$(this).prop("href").match(/((email|order|phone|num)=\s*?(.+))&/)[1] //"email=email#test.net"
$(this).prop("href").match(/((email|order|phone|num)=\s*?(.+))&/)[3] //"email#test.net"
The above just puts the part without the & into a capture group. You could also use a positive lookahead:
$(this).prop("href").match(/(email|order|phone|num)=\s*?(.+)(?=&)/) //["email=email#test.net", "email", "email#test.net"]
Just use a lookahead:
(email|order|phone|num)=\s*?(.+)(?=&)
It will not "eat" the ampersand.