Ulysses
General => Off-Topic => Topic started by: Bryantdl7 on September 22, 2015, 10:23:24 AM
-
So I am trying to find a way to delete all strings that contain "new" in the script structure below
"STEAM_0:0"
{
"name" "mX"
"deny"
{
}
"allow"
{
}
"group" "new"
}
However, as you can tell I am working with steam ID's so it is not as simple as imputting it into ms word and doing a replace action, I want to delete everything I put inside that code box above. I was wondering if anyone knows of a program that can delete the entire string if it contains a certain variable, such as "group" "new"
I am cleaning out my users.txt file as it has over 41 thousand lines, and i want to quickly delete everyone from the database while saving my staff from being deleted.
If I confused you guys I can try and explain it better
-
Use notepad++'s replace feature. It accepts regex expressions and you can just replace it with nothing.
"STEAM_0:(0|1):\d+"\s\n{\n\s
matches a steamid followed by the first brace and some spaces and newlines
"deny"\s\n\s{\n\s\}\n\s
matches "deny" followed by some spaces, new lines, and braces
"allow"\s\n\s{\n\s\}\n\s
matches "allow" followed by some spaces, new lines, and braces
"name"\s".+\n\s
matches "name" and someones name, followed by some spaces and new lines
"group"\s"new"\n\}\n
matches "group" and "new", followed by some spaces and new lines and the closing brace and then another newline
all put together:
"STEAM_0:(0|1):\d+"\s\n{\n\s"deny"\s\n\s{\n\s\}\n\s"allow"\s\n\s{\n\s\}\n\s"name"\s".+\n\s"group"\s".+"\n\}\n
Of course because of the genius of users.txt, the deny, allow, and name fields can be in any order. Hip hurray! (I'm sure there must be a good reason for this, and I'm curious what that reason is. It's just also pretty irritating.)
Just go ahead and re-order those three elements (total of six possible combinations) and you should be able to get them all.
-
Thank you so much! It worked perfectly! users.txt 407kb down to 41 kb!
+Rep
-
Use notepad++'s replace feature. It accepts regex expressions and you can just replace it with nothing.
I really need to learn more about regex haha, looks powerful.
-
Yea I've never used it before, but it seemed like it would work for this. I just used an online regex tester that also had a regex cheatsheet. It was much easier than I expected.
-
RegEx is awesome and used in so many different coding/scripting languages for string manipulation it's incredible.
I too never learned even 1% of what it can do.
RoastChicken, though I'm sure we could all find one or two using Google, you should share your link that helped you.
-
The site I used was https://regex101.com/ (https://regex101.com/), but as you said there are tons of regex testers out there. I like this site in particular because it explains what each character in your command does, so you can find mistakes more easily.