Jump to content

StringRegExp - Need Help Creating


Recommended Posts

Hello,

I would like to take the info below and StringRegExp out the FFF84F1. If I have just FFF84F1 I can use

^([a-zA-Z0-9]{4}|[a-zA-Z0-9]{6})[a-zA-Z0-9]$
and find it just fine. But with all the other letters, whitespace and multiline I'm not able to make my first code work. I'm not very strong in RegEx and if someone could help me out that would be great.

(I added a "." at the end to help show the extra white space after it.)

Caption               IdentifyingNumber  Name           Vendor   Version  


Computer System Product  FFF84F1            Latitude E6420  Dell Inc.  01     





.
Edited by Crazyace

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

you may want to consider stringsplit if that document is already tab delimited.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

you may want to consider stringsplit if that document is already tab delimited.

Thanks, I'll check out the help file on that one.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

I checked on the splitstring and I'm not sure it can help me. Do you think if I use it in an array I could call the array that it puts it in and then find it?

I tested with _ArrayDisplay and got

[0]|4

[1]|Caption               IdentifyingNumber  Name           Vendor   Version

[2]|Computer System Product  GXM84R1            Latitude E6420  Dell Inc.  01     

[3]|

[4]|

I'm going to guess that the "|" are added from doing a copy from the ListView Display pop up that _ArrayDisplay Does

Edited by Crazyace

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

Maybe StringBetween could also help you out.

If you are able to describe in words what rule is needed, then I could create the regex pattern for you.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

$str = 'Caption            IdentifyingNumber  Name         Vendor   Version  ' & @CRLF & _
  'Computer System Product  FFF84F1         Latitude E6420  Dell Inc.  01  ' 
$pattern = 'Products+(.*?)s+w+'
$re = StringRegExp($str, $pattern, 3)
ConsoleWrite($re[0] & @LF)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Maybe StringBetween could also help you out.

If you are able to describe in words what rule is needed, then I could create the regex pattern for you.

Thanks for the tip I'll check on that also. The only thing that will change is
FFF84F1         Latitude E6420  Dell Inc.  01

Well Dell Inc, should stay but the FF84F1, Latitude E6420, and 01 will change. I built

^([a-zA-Z0-9]{4}|[a-zA-Z0-9]{6})[a-zA-Z0-9]$
off of just using FFF84F1 if that helps you any.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

$str = 'Caption            IdentifyingNumber  Name         Vendor   Version  ' & @CRLF & _
  'Computer System Product  FFF84F1         Latitude E6420  Dell Inc.  01  '
$pattern = 'Products+(.*?)s+w+'
$re = StringRegExp($str, $pattern, 3)
ConsoleWrite($re[0] & @LF)

Sorry my reply was slow on that. Testing this now and will let you know soon :-)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

Caption               IdentifyingNumber  Name           Vendor   Version  


Computer System Product  FFF84F1            Latitude E6420  Dell Inc.  01    





.

Where is this data coming from? Maybe there's a more organized way of querying the same data and omitting the 2nd column of info?
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I was thinking along these lines...certainly will need more accurate expressions when the chances for overlap increase (mine just looks for seven alphanumerics then the second makes sure there is a number to eliminate the ass end of all the words i picked up), but you will find plenty of help there.

#include<array.au3>

$Fread = fileread("test.txt")

$ASplit = StringSplit($Fread , @tab)

;_ArrayDisplay($ASplit)

for $i = 1 to ubound($ASplit) - 1
    If stringregexp($ASplit[$i] , "(wwwwwwwz)") = 1 Then
        If stringregexp($ASplit[$i] , "(d)") = 1 Then msgbox (0, '' , "ID number: " & $ASplit[$i])
        Else
    EndIf
Next

test.txt

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

After thinking about it, I wouldn't be able to use this. Your example works fine, but I'm pulling this from the console window. I'm not sure how I could use @CRLF with reading from the console.

Here is the code that I have to do that.

Local $pid = Run("wmic csproduct list brief", @SystemDir, @SW_HIDE, $STDOUT_CHILD) ;wmic isn't an internal command to CMD
ProcessWaitClose($pid) ;better than loops
$output = StdoutRead($pid)
ConsoleWrite($output)
$array = StringSplit($output, @CRLF, 1)
_ArrayDisplay($array)

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

Cannot test it, but maybe something like this

#Region    ;************ Includes ************
#Include <Array.au3>
#EndRegion ;************ Includes ************
$pattern = 'Products+(.*?)s+w+'
$values = _getDOSOutput('wmic csproduct list brief') & @CRLF)
ConsoleWrite($values & @LF)
$re_Array = StringRegExp($str, $pattern, 3)
_ArrayDisplay($re_Array)
Func _getDOSOutput($command)
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
   $text &= StdoutRead($Pid, False, False)
   If @error Then ExitLoop
   Sleep(10)
WEnd
Return $text; StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

post 6 + post 11

#include<Constants.au3>

Local $pid = Run("wmic csproduct list brief", @SystemDir, @SW_HIDE, $STDOUT_CHILD) ;wmic isn't an internal command to CMD
ProcessWaitClose($pid) ;better than loops
$output = StdoutRead($pid)
ConsoleWrite($output)
$array = StringSplit($output, @CRLF, 1)
$pattern = 'Products+(.*?)s+w+'
For $i = 0 to ubound($array) - 1
$re = StringRegExp($array[$i], $pattern , 3)
If isarray($re) Then
ConsoleWrite($re[0] & @LF)
ExitLoop
Endif
Next
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

post 6 + post 11

#include Local $pid = Run("wmic csproduct list brief", @SystemDir, @SW_HIDE, $STDOUT_CHILD) ;wmic isn't an internal command to CMD ProcessWaitClose($pid) ;better than loops $output = StdoutRead($pid) ConsoleWrite($output) $array = StringSplit($output, @CRLF, 1) $pattern = 'Products+(.*?)s+w+' For $i = 0 to ubound($array) - 1 $re = StringRegExp($array[$i], $pattern , 3) If isarray($re) Then ConsoleWrite($re[0] & @LF) ExitLoop Endif Next
Thanks everyone for all of your help and very quick replies. boththose, I was able to integrate your code into my project and it works great!

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

This example:-

ConsoleWrite(StringRegExpReplace(FileRead("test.txt"), "(?s)^(?:.+?\v+.+?\h{2,})(.+?)\h{2,}.*$", "$1") & @LF)

returns FFF84F1

from:-

Caption               IdentifyingNumber  Name           Vendor   Version  


Computer System Product  FFF84F1            Latitude E6420  Dell Inc.  01     





.

That is, the code in the quote is the contents of the "test.txt" text file.
Link to comment
Share on other sites

This example:-

ConsoleWrite(StringRegExpReplace(FileRead("test.txt"), "(?s)^(?:.+?v+.+?h{2,})(.+?)h{2,}.*$", "$1") & @LF)
returns FFF84F1 from:- That is, the code in the quote is the contents of the "test.txt" text file.
Thanks Malkey this works great also!

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...