问题
I have this list below:
originalscrape,scrapeDate,userId,username,full_name,is_private,follower_count,following_count,media_count,biography,hasProfilePic,external_url,email,contact_phone_number,address_street,isbusiness,Engagement %,MostRecentPostDate,AvgLikes,AvgComments,category,businessJoinDate,businessCountry,businessAds,countryCode,cityName,isverified
,07/03/2020 05:54 AM,="189389157",stronger_together_forever,stronger_together_forever 🌈🏖☀️,False,0,0,0,,False,,,,,No,0,Has no posts.,0,0,,,,,,,No
,07/03/2020 05:54 AM,="51807820",aaronistattoo,Aaron Is.,False,0,0,0,,False,,,,,No,0,Has no posts.,0,0,,,,,,,No
,07/03/2020 05:54 AM,="194962598",djcoley727,djcoley727,False,0,0,0,,False,,,,,No,0,Has no posts.,0,0,,,,,,,No
,07/03/2020 05:54 AM,="4182106610",cesararce1985,Cesar Arce,False,0,0,0,,False,,,,,No,0,Has no posts.,0,0,,,,,,,No
,07/03/2020 05:54 AM,="8957742561",minkwhiz,𝕄𝕚𝕟𝕜𝕎𝕙𝕚𝕫,False,0,0,0,,False,,,,,No,0,Has no posts.,0,0,,,,,,,No
I would like to get the userIds only as below:
189389157
51807820
194962598
4182106610
8957742561
I've used ^(?:[^,\r\n]*,){3}([^,\r\n]+).* but it gets me "Usernames", I want is Userids.
I wish somebody who can help me to find the right Regex to extract the userids only.
Thank you
回答1:
Use the advantage the time in the AM/PM format is present before each ID as well as the ID is surrounded with " characters:
(?:AM|PM),=\"(\d+)\"
Check the demo at Regex101.
回答2:
You could use Match the =" and repeat the group 2 times instead of 3. Then capture 1+ digits.
Note to repeat the character class [^,\r\n] using * for 0 or more times.
If you want the digits only, you could replace with group 1 using $1
^(?:[^,\r\n]*,){2}="(\d+)".*
^Start of string(?:[^,\r\n]*,){2}Repeat 2 times matching 0 or more times any char except a comma or a newline, then match,="Match literally(\d+)Capture group 1, match 1+ digits".*Match " and match the rest of the line
Regex demo
If you want the match only, you could make use of \K to reset the match buffer, then match the digits and assert a double quote on the right.
^(?:[^,\r\n]*,){2}="\K\d+(?=")
Regex demo
来源:https://stackoverflow.com/questions/62723201/notepad-regex-how-to-extract-userid-from-this-list