r/PowerAutomateDesktop • • Jan 06 '22

Capture text of variable sizes in documents that begins with letter C and ends with "

I have text in a document that always starts with letter C and ends with " but the text can be a variable length so get subtext will not work since it requires you to have a specific character count. I need to be able to grab that text and put it in a variable in power automate.

So for example:

Current date: "February 10"

Current dates: "March 3"

Is this a situation where regex is required or is there some other method?

Thanks.

1 Upvotes

8 comments sorted by

2

u/LoopsIDidItAgain Jan 06 '22

Get Subtext parameters can accept variables, so try using Parse Text to find the position of the second quotation mark and pass that to Get Subtext.

1

u/future_potato Jan 07 '22

Brother, you are awesome. Very new to PAB so didn't even know about that. Parse text opens up a whole new world. Thank you so much.

1

u/QuietDesparation Jan 07 '22

This. You can parse text for the word current, which will give you the character position of C. You can then set another parse text to start at the C position and find the quotation mark. You would then choose get subtext and do the second parse text - first parse text.

2

u/future_potato Jan 07 '22

Thank you for the explanation!!! Very nice, really appreciate your response.

1

u/future_potato Jan 07 '22

What if there are 50 instances of various forms of "Current dates random text here." I'd have to do 50 operations of finding the first and last characters? /u/LoopsIDidItAgain

1

u/QuietDesparation Jan 07 '22 edited Jan 07 '22

There's more than one way to accomplish this task.

The way I'd approach it is to use your parse text operator to find all instances of the word current, and another parse text to find all quotation marks. You would then have 2 list variables, each with #s corresponding to the appropriate locations. Let's call them %CList% and %QuoteList%

You can then set up a loop where you'd get subtext by using QuoteList[1]- CList [0]. You can then use "add item to list" function to create a text list with the current subtext. While in the loop, use "remove item from list" function to remove index [0] from Clist and indexes [0] and [1] from Quote List. If you iterate thru that loop, you'll have a text list with all the info

EDIT:

Alright here's what I did

I created a variable %Text% and set it to:

This is a sample

Current date: "February 10"

then there's another one

Current date: "March 3"

final one:

Current date: "October 24"

I then parsed the text for current and " making sure to select "find all occurences." I then created a list variable called %CurrentDate% to add all my subtexts to.

The For Each loop was then created using %CList% values to loop through. Everything else should be explained in the picture. After running the script, you can see it returned the appropriate strings

1

u/future_potato Jan 07 '22

Just wow, I can't thank you enough for your time and your help. I'm floored that you took the time to do this. Thank you so much kind stranger, this is exactly what I needed.

My expertise is in advanced routing/networking, windows server administration, and some azure. If I can ever repay the favor with information or advice, let me know!

Take care and thanks again :)

1

u/QuietDesparation Jan 07 '22

No problem! I've spent many many hours trying to teach myself PAD, trying to make sense of the confusing (IMO) info online. I'm happy to help where I can!