how to replace the particular string in-between paragraph in DB2 - string

In the below string, i need to replace the string as space (' ') which starts from DND_NCP_TEXT_START and end at DND_NCP_TEXT_END. without hardcode the string or without store it in variable. any possible using regular expression?
String:
'Dear DND_CST_NAME_STARTHARRIET SCOTT
:DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY SHORT
:DND_NCP_NAME_END
DND_ATTORNEY_TEXT_START
Our records indicate that you represent
DND_CST_NAME_STARTHARRIET D SCOTT
DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY A SHORT
DND_NCP_NAME_END in the above referenced child support matter. Please contact your client regarding this matter and advise us as soon as possible.
If you are no longer representing
DND_CST_NAME_STARTHARRIET D SCOTT
DND_CST_NAME_END
DND_NCP_NAME_STARTHARRY A SHORT
DND_NCP_NAME_END, please file a Notice of Withdrawal.
DND_ATTORNEY_TEXT_END'
needed output:
start string DND_NCP_NAME_START and end string DND_NCP_NAME_END and string inside this need to remove

The problem of your expression is, that you have 2 such patterns in the text, but since the default algorithm used is greedy one, the whole string starting from the 1-st DND_NCP_TEXT_START and ending with the last DND_NCP_TEXT_END is removed.
Use non-greedy matching (.*?) as in the example below.
SELECT
REGEXP_REPLACE
(
'DND_ATTORNEY_TEXT_START Dear EDWIN Our records indicate that you represent HARRIET D SCOTT in the above referenced child support matter. DND_NCP_TEXT_START Please contact your client regarding this matter and advise us as soon as possible.DND_NCP_TEXT_END Please co-operate.DND_NCP_TEXT_START Please contact your client regarding this matter and advise us as soon as possible.DND_NCP_TEXT_END We are anticipating your reply. Thanks a lot. DND_ATTORNEY_TEXT_END'
,'DND_NCP_TEXT_START.*?DND_NCP_TEXT_END',''
)
FROM SYSIBM.SYSDUMMY1;

Related

Regex or IndexOf?

I have a long string "AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41". I have to extract integer value after "IP-" i.e 1 (only) what is the most efficient way ? I am using c#
Thanks
The 'most-efficient' way depends on how consistent your string is in terms of length and appearance. You can surely do this with a regular expression as a quick solution if you just want to get the digit directly following IP-.
You can utilize the RegularExpressions API, passing in your regular expression and input string.
https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.match?view=netframework-4.8#System_Text_RegularExpressions_Regex_Match_System_String_System_String_
This pattern should get you started IP-[0-9]; refine it more to your use case as needed.
For example:
Match matched = System.Text.RegularExpressions.Match(
"AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41",
"IP-[0-9]"
);

BluePrism count number of times a character exists in a string

I have a calculation which will remove a blank space and replace with a full stop. This is correct for 90% of my cases. However, sometimes two blanks will appear in my value. For the second space I want to delete it. Is this possible?
I think it may be possible using a code stage, but I am not sure what the code would be.
My current calculation is Replace([Item Data.Name], " ", ".")
Example data John B Smith I want the result to be John.BSmith
For anything that'd like to do with the strings, there is a really powerful tool called Regular Expressions (regex). I encourage you to play with it, because it's a really powerful tool in the hands of RPA developer.
To replace the second space in any string with a "." you can use the following action.
Object: Utility - Strings
Action: Regex - Find and Replace
Input:
Regex Pattern: "(?<= .*) "
Text: "John B Smith"
Replacement: "."
The above action is not a standard Blueprism one, so it has to be added to your VBO. The action looks as follows:
The VB.net code for that action is as follows:
Dim R as New Regex(Regex_Pattern, RegexOptions.SingleLine)
Dim M as Match = R.Match(Text)
replacement_result = R.Replace(Text,Regex_Pattern,replacement_string)
There might be a need for some additional assemblies, so please see below a printscreen of references and namespaces used in my object:
I resolved this issue by using the Utility - Strings object and the split text action. I split my name by space. This outputted a collection which I was then able to loop through and add a full stop after the fist instance but then trim the other instances.
Please see screenshot
I think the simplest solution would be
Replace(Replace(Text," "," ")" ","."))
if you know that it will give one or two spaces
First replace the two white spaces to single and then again single white space to dot(.)

Compare a user input to a list python3

Hey guys so I tried looking at previous questions but they dont answer it like my teacher wants it to be answered. Basically i need to get a string from a user input and see if it has:
at least one of [!,#,#,$,%,^,&,*,(,)] (non-letter and nonnumeric
character)
o Create a list for these special characters
I have no idea how to make a def to do this. Please help!
You should probably look into Regular expressions. Regular expressions allow you to do many string operations in a concise way. Specifically, you'll want to use re.findall() in order to find all special characters in your string and return them. You can check if the returned list has length 0 to check if there were any special characters at all.
With regards to building the regular expression to find special characters itself... I'm sure you can figure that part out ;)
Please try the below
import re
inputstring = raw_input("Enter String: ")
print inputstring
print "Valid" if re.match("^[a-zA-Z0-9_]*$", inputstring) else "Invalid"

Read a string and create an acronym from the first initial letter of every word on the string

I just wrote a code with the criteria above, but it doesn't seem to work properly because I either miss a letter at the end or in the middle.
Could anyone please check out my code an tell me what I'm doing wrong. By the way I already checked other threads on this similar problem, but I'm not allowed to use regex or print function.
phrase=('my room is cold')
allSpaces=findstr(' ',phrase);
k=length(allSpaces)
acr=phrase(1:allSpaces(1):allSpaces(k)-1)
Output:
acr= mrms
Change last line to
acr = phrase([1 allSpaces+1])
That way you get the first letter, and then the first after each space.

parsing a string that ends

I have a huge string. I need to extract a substring from that that huge string. The conditions are the string starts with either "TECHNICAL" or "JUSTIFY" or "ALIGN" and ends with a number( any number from 1 to 10) followed by period and then followed by space. so for example, I have
string x = "This is a test, again I am testing TECHNICAL: I need to extract this substring starting with testing. 8. This is test again and again and again and again.";
so I need this
TECHNICAL: I need to extract this substring starting with testing.
I was wondering if someone has elegant solution for that.
I was trying to use the regular expression, but I guess I could not figure out the right expresion.
any help will be appreciated.
Thanks in advance.
Try this: #"((?:TECHNICAL|JUSTIFY|ALIGN).*?)(?:[1-9]|10)\. "

Resources