ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Extract REGEX matches from multiple text files

<< < (10/22) > >>

kalos:
I don't understand what CDATA is.

My xml file contains tons of tags, ie text inside <>, in a complex hierarchy.
Apart from that, it contains values both inside the <>, in the format of <someTag someID="SomeValue"> and in the format of <someTag>SomeValue<\someTag>

1) I don't know what the total number and hierarchy of tags is. So can I select ALL nodes under the whole hierarchy?
2) Will PS process the both formats of values above?

kalos:
Guys, the more I am looking on it, the more I am convinced that Regex would be the best solution.
-kalos (August 06, 2018, 11:36 AM)
--- End quote ---
Please listen to people with more (programming) experience than you have, you are really trying to hammer round screws into square holes here, don't do that, you'll hurt yourself.
-Ath (August 06, 2018, 02:14 PM)
--- End quote ---

OK but I would be highly interested to learn how to do the below?
Can anyone tell me please how to find a regex in a file and append it to a file? Also, how to loop that? Last, how to find the next regex match in the file?

Ath:
Can anyone tell me please how to find a regex in a file and append it to a file? Also, how to loop that? Last, how to find the next regex match in the file?
-kalos (August 06, 2018, 02:27 PM)
--- End quote ---
Well, the trouble is you'll have to do it in some script or programming language, as regex is actually a selection mechanism using pattern matching ('regular expressions').
For such a task I'd advise to use sed, the Stream EDitor, originally from unix, but also available for Windows, that is built for jobs like this.
I've made a Sed-Tester tool for NANY a couple years back, find it from the link below this post and try it out, it includes sed.exe, and has a link to sed documentation in the gui.
You can also continue on the PS-script 4wd gave here earlier, but that doesn't go through the data sequentially in the way sed does.

kalos:
Stream EDitor
-Ath (August 06, 2018, 02:45 PM)
--- End quote ---

Very interesting tool, thanks!

4wd:
Can anyone tell me please how to find a regex in a file and append it to a file? Also, how to loop that?-kalos (August 06, 2018, 11:36 AM)
--- End quote ---

That is what the code I originally posted does.

Last, how to find the next regex match in the file?
--- End quote ---

Add another Select-String line with the next RegEx.

I'm going to give up until we get at least sensible raw data and what the expected output should look like ...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version