String manipulation with dynamic values

Hi all,

I have this string: “04-2022-7000800426 Pagament Quotes Seguretat Social octubre 2021”
and I need to replace these values “7000800426” and “octubre 2021” wich can be whatever. So when I go find a file, I can do like this: “04-2022-” + (7000800426) + (“Pagament Quotes Seguretat Social”) + (octubre 2021)"
I mean, I need to be able to find the file by changing the first date (“04-2022”)

Thank you in advance!

Hi @domingo.ruiz

In this “04-2022-7000800426 Pagament Quotes Seguretat Social octubre 2021”

is ‘04-2022-’ format is always same? and does the string always contain ‘Pagament Quotes Seguretat Social’ ? or the ‘Octubre 2021’ will always be at the last?

Can you confirm these please

cheers

Hi @Anil_G

The format will be always the same. I made a regex to be able to change the first date, but this number: 7000800426 will change, the same with october2021.

Thanks!

What is the Output for that string? @domingo.ruiz

Hi @Gokul001

“Pagament Quotes Seguretat Social” will remain the same. Octubre 2021 will change, and this number 7000800426 too. So the output would be: the date i need to look for (04-2022) for example + 7000800426 (that will change everytime) + Pagament Quotes Seguretat Social + octubre 2021 that will also change

thank you again

HI @domingo.ruiz

How about this expression

System.Text.RegularExpressions.Regex.Replace(YourString,"(?=Pagament)|(?<=\b\d{2}-\d{4}\b)|(?<=Social)","+").Tostring

Output will be 04-2022+-7000800426 +Pagament Quotes Seguretat Social+ octubre 2021

image

Regards
Gokul

image

Thank you guys,

maybe I should explain better or I didnt understand.
This is what I have:
var Month = 06
var Year = 2021
var String = “04-2022-7000800426 Pagament Quotes Seguretat Social octubre 2021”
This is the output:
{Month-Year} + {unkown number} + “Pagament Quotes Seguretat Social” + {unkown month} + {unkown year}

I did this to change the first date:
System.Text.RegularExpressions.Regex.Replace( String,“(\d{2}\W\d{2,4})”, Month+ “-” + Year)
And it works but I need another Regex for {unkown number}{unkown month}{unkown year}

Thanks again

HI @domingo.ruiz

How about this expression

It will take only the Number

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\b\d{2}-\d{4}\b\s)\d*").Tostring

image

It will get the Number and Content

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=\b\d{2}-\d{4}\b\s)\d* Pagament Quotes Seguretat Social").Tostring

image

This will get only the word in the input

System.Text.RegularExpressions.Regex.Match(YourString,"Pagament Quotes Seguretat Social").Tostring

image

As you said the Pagament Quotes Seguretat Social is constant so you can just type the content in the regex

Regards
Gokul

Hi @domingo.ruiz

For matching the month and year you already have a regex so now for matching {unknown month} and {unknown year} use the following

(\w+ \d+)(?!.*\d)

System.Text.RegularExpressions.Regex.Replace( String,“(\w+ \d+)(?!.*\d)”, unknownMonth+ “ ” + unknownYear)

Here month and year the month and year you want in place of octubre 2021

for {unkown number} use this

(\d+)(?=\sPagament Quotes Seguretat Social)

System.Text.RegularExpressions.Regex.Replace( String,“(\d+)(?=\sPagament Quotes Seguretat Social)”, unknownNumber)

Hope this is what you are looking for

cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.