guner7 Posted September 9, 2019 Posted September 9, 2019 Hello, I need some help to parse the Green highlighted value with from below text: RESISTOR THICK FILM 4.64K ±1% 1/4W ±100PPM/°C 1206 SMT RESISTOR THICK FILM 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT RESISTOR CARBON FILM 22K ±10% 1/2W AXIAL THT RESISTOR WIREWOUND 22 ±5% 3W ±30PPM/°C AXIAL THT RESISTOR METAL OXIDE 4.7K ±5% 2 W ±300PPM/°C AXIAL THT RESISTOR THICK FILM 0 1/8W 0805 SMT I am using positive look behind.: (?<=FILM|WOUND|OXIDE).+ Can only pull this off: 4.64K ±1% 1/4W ±100PPM/°C 1206 SMT 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT 22K ±10% 1/2W AXIAL THT 22 ±5% 3W ±30PPM/°C AXIAL THT 4.7K ±5% 2 W ±300PPM/°C AXIAL THT 0 1/8W 0805 SMT I'm trying the \b word boundary to no avail at this point. Appreciate if anyone would guide me on this?
FrancescoDiMuro Posted September 9, 2019 Posted September 9, 2019 @guner7 You don't need to use lookbehind (even if you could), and since you are trying to extract digit(s) only, plus the character K (which could be replaced as \w* if you have any other engineering unit), you could use a pattern like this one: '(?:FILM|WIREWOUND|OXIDE)\s*(\d+\.?\d*K?)' guner7 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
guner7 Posted September 9, 2019 Author Posted September 9, 2019 9 minutes ago, FrancescoDiMuro said: '(?:FILM|WIREWOUND|OXIDE)\s*(\d+\.?\d*K?)' That works like charm. Thank you. Why \s* able to tell regex not to capture?
FrancescoDiMuro Posted September 9, 2019 Posted September 9, 2019 @guner7 You're welcome. 1 hour ago, guner7 said: Why \s* able to tell regex not to capture? Everything that is in a pair of round parenthesis is captured, as long as there's no captouring groups, atomic groups, or lookaround. Since the \s* is outside the round parenthesis, it is not captured guner7 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
iamtheky Posted September 9, 2019 Posted September 9, 2019 think you can also pull it off focusing on the K (or lack thereof) #include<array.au3> $s = "RESISTOR THICK FILM 4.64K ±1% 1/4W ±100PPM/°C 1206 SMT" & @LF & _ "RESISTOR THICK FILM 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT" & @LF & _ "RESISTOR CARBON FILM 22K ±10% 1/2W AXIAL THT" & @LF & _ "RESISTOR WIREWOUND 22 ±5% 3W ±30PPM/°C AXIAL THT" & @LF & _ "RESISTOR METAL OXIDE 4.7K ±5% 2 W ±300PPM/°C AXIAL THT" & @LF & _ "RESISTOR THICK FILM 0 1/8W 0805 SM" $a = stringregexp(stringstripws($s , 4) , "(?m)(\d+\.*\d*?K*)(?:\s+).*" , 3) _ArrayDisplay($a) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted September 9, 2019 Posted September 9, 2019 And assuming that there are no digits in the item names, it could even be done like this $a = stringregexp($s, "(?m)^\D+(\S+)" , 3) ... my 2 cents iamtheky 1
jchd Posted September 9, 2019 Posted September 9, 2019 Don't forget resistors of high and low values: MΩ, GΩ (if working with very high voltage), mΩ and even µΩ (e.g. current sense resistors). Also, kilo is k, not K but that is possible to cope with this. It's probable that a BOM can refer to "CAPACITOR MKP X2", hence digits in designations may occur, depending on the nomenclature used. Provided fractional values have a leading zero (e.g. 0.27 = 270mΩ): #include <array.au3> Local $sRes = "RESISTOR THICK FILM 4.64K ±1% 1/4W ±100PPM/°C 1206 SMT" & @LF & _ "RESISTOR METAL STIRP 4.7m ±0.5% 3 W ±100PPM/°C AXIAL THT" & @LF & _ "RESISTOR THICK FILM 3.83K ±1% 1/4W ±100PPM/°C 1206 SMT" & @LF & _ "RESISTOR CARBON FILM 22K ±10% 1/2W AXIAL THT" & @LF & _ "RESISTOR WIREWOUND 22 ±5% 3W ±30PPM/°C AXIAL THT" & @LF & _ "RESISTOR METAL OXIDE 4.7K ±5% 2 W ±300PPM/°C AXIAL THT" & @LF & _ "RESISTOR METAL OXIDE 1.13G ±1% 1/2 W ±50PPM/°C AXIAL THT" & @LF & _ "RESISTOR THICK FILM 0 1/8W 0805 SM" $a = StringRegExp($sRes, "(?m)^[\w\s]+\s(\d+\.?\d*[GMKmµ]?)\s", 3) _ArrayDisplay($a) guner7 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now