# ripgrep search
### Tested against Windows / Python 3.11 / Anaconda
### pip install rgsucher
```PY
from rgsucher import rg_search
import numpy as np
# searching in a folder
wholeregex = r"\d+"
imagefile = r"C:\Users\hansc\Documents\fubax\Disable-IPv6\common" # folder
server_ip = rg_search(
regex=wholeregex,
file_or_folder=imagefile,
rgexe=r"C:\ProgramData\chocolatey\bin\rg.exe",
binary=True,
multiline_dotall=False,
multiline=False,
ignore_case=False,
invert_match=False,
case_sensitive=False,
crlf=False,
word_regexp=False,
fixed_strings=False,
)
# searching in a file
allregex = [
r"""\s*<string name=\"server_ip\">\d{3}.\d{3}.\d{3}.\d{3}</string>""",
r"""\s*<string name=\"Defaultserver\">\d{3}.\d{3}.\d{3}.\d{3}</string>""",
r"""\s*<string name=\"server_port\">\d{5}</string>""",
r"""\s*<int name=\"Defaultport\" value=\"\d{5}\" />""",
]
wholeregex = r"(?:(?:" + ")|(?:".join(allregex) + "))"
imagefile = r"C:\ProgramData\BlueStacks_nxt\Engine\Rvc64_42\Data.vhdx" #file
server_ip = rg_search(
regex=wholeregex,
file_or_folder=imagefile,
rgexe=r"C:\ProgramData\chocolatey\bin\rg.exe",
binary=True,
multiline_dotall=False,
multiline=False,
ignore_case=False,
invert_match=False,
case_sensitive=False,
crlf=False,
word_regexp=False,
fixed_strings=False,
add_to_cmd="",
)
# replacing the matches using numpy
import re
print(server_ip)
myip = "112.112.131.121"
myport = "55164"
with open(imagefile, "rb") as f:
imagedata = f.read()
nparray = np.frombuffer(imagedata, dtype=np.uint8).copy()
for k, v in server_ip.items():
for submatch in v["submatches"]:
print(submatch)
original = submatch[0]
new = re.sub(r">\d{3}.\d{3}.\d{3}.\d{3}<", rf">{myip}<", original)
new = re.sub(r">\d{4,5}<", rf">{myport}<", new)
if len(new) > len(original):
new = new[1:]
new = re.sub(r'"\d{4,5}"', rf'"{myport}"', new)
if len(new) > len(original):
new = new[1:]
print(new, original)
replacem = new.encode()
replacemint = list(replacem)
coun = 0
for i in range(submatch[1], submatch[2]):
nparray[i] = replacemint[coun]
coun += 1
with open(imagefile, "wb") as f:
f.write(nparray.tobytes())
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/rgsucher",
"name": "rgsucher",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "ripgrep, regex",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5b/32/fb9ff0bef19c05c2782a0e2a25c2b6ab82d49811b1a22135db9007bd815e/rgsucher-0.11.tar.gz",
"platform": null,
"description": "\r\n# ripgrep search\r\n\r\n### Tested against Windows / Python 3.11 / Anaconda\r\n\r\n### pip install rgsucher\r\n\r\n```PY\r\nfrom rgsucher import rg_search\r\nimport numpy as np\r\n\r\n# searching in a folder\r\nwholeregex = r\"\\d+\"\r\nimagefile = r\"C:\\Users\\hansc\\Documents\\fubax\\Disable-IPv6\\common\" # folder\r\nserver_ip = rg_search(\r\n regex=wholeregex,\r\n file_or_folder=imagefile,\r\n rgexe=r\"C:\\ProgramData\\chocolatey\\bin\\rg.exe\",\r\n binary=True,\r\n multiline_dotall=False,\r\n multiline=False,\r\n ignore_case=False,\r\n invert_match=False,\r\n case_sensitive=False,\r\n crlf=False,\r\n word_regexp=False,\r\n fixed_strings=False,\r\n)\r\n\r\n# searching in a file\r\nallregex = [\r\n r\"\"\"\\s*<string name=\\\"server_ip\\\">\\d{3}.\\d{3}.\\d{3}.\\d{3}</string>\"\"\",\r\n r\"\"\"\\s*<string name=\\\"Defaultserver\\\">\\d{3}.\\d{3}.\\d{3}.\\d{3}</string>\"\"\",\r\n r\"\"\"\\s*<string name=\\\"server_port\\\">\\d{5}</string>\"\"\",\r\n r\"\"\"\\s*<int name=\\\"Defaultport\\\" value=\\\"\\d{5}\\\" />\"\"\",\r\n]\r\nwholeregex = r\"(?:(?:\" + \")|(?:\".join(allregex) + \"))\"\r\nimagefile = r\"C:\\ProgramData\\BlueStacks_nxt\\Engine\\Rvc64_42\\Data.vhdx\" #file\r\nserver_ip = rg_search(\r\n regex=wholeregex,\r\n file_or_folder=imagefile,\r\n rgexe=r\"C:\\ProgramData\\chocolatey\\bin\\rg.exe\",\r\n binary=True,\r\n multiline_dotall=False,\r\n multiline=False,\r\n ignore_case=False,\r\n invert_match=False,\r\n case_sensitive=False,\r\n crlf=False,\r\n word_regexp=False,\r\n fixed_strings=False,\r\n add_to_cmd=\"\",\r\n)\r\n\r\n# replacing the matches using numpy\r\nimport re\r\n\r\nprint(server_ip)\r\nmyip = \"112.112.131.121\"\r\nmyport = \"55164\"\r\nwith open(imagefile, \"rb\") as f:\r\n imagedata = f.read()\r\nnparray = np.frombuffer(imagedata, dtype=np.uint8).copy()\r\n\r\nfor k, v in server_ip.items():\r\n for submatch in v[\"submatches\"]:\r\n print(submatch)\r\n original = submatch[0]\r\n new = re.sub(r\">\\d{3}.\\d{3}.\\d{3}.\\d{3}<\", rf\">{myip}<\", original)\r\n new = re.sub(r\">\\d{4,5}<\", rf\">{myport}<\", new)\r\n if len(new) > len(original):\r\n new = new[1:]\r\n new = re.sub(r'\"\\d{4,5}\"', rf'\"{myport}\"', new)\r\n if len(new) > len(original):\r\n new = new[1:]\r\n print(new, original)\r\n\r\n replacem = new.encode()\r\n replacemint = list(replacem)\r\n coun = 0\r\n for i in range(submatch[1], submatch[2]):\r\n nparray[i] = replacemint[coun]\r\n coun += 1\r\nwith open(imagefile, \"wb\") as f:\r\n f.write(nparray.tobytes())\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "ripgrep search",
"version": "0.11",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/rgsucher"
},
"split_keywords": [
"ripgrep",
" regex"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "408a13aa5319dc69246374f96102ddda6f8ec6d68c6c17f117773d07cde82506",
"md5": "89981901eac5057e27bea50f868e008c",
"sha256": "32217e9c45212999d1699776d2a0b635d7438f5d2f5bd4a4fe969f1952bf6a85"
},
"downloads": -1,
"filename": "rgsucher-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "89981901eac5057e27bea50f868e008c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8659,
"upload_time": "2024-03-29T00:54:28",
"upload_time_iso_8601": "2024-03-29T00:54:28.844538Z",
"url": "https://files.pythonhosted.org/packages/40/8a/13aa5319dc69246374f96102ddda6f8ec6d68c6c17f117773d07cde82506/rgsucher-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5b32fb9ff0bef19c05c2782a0e2a25c2b6ab82d49811b1a22135db9007bd815e",
"md5": "d1d61cc283153c441744e63f21cd189b",
"sha256": "0369a418b59c4f57c8713a53b800ef03743adf86597298c2483c48e5cb9b5946"
},
"downloads": -1,
"filename": "rgsucher-0.11.tar.gz",
"has_sig": false,
"md5_digest": "d1d61cc283153c441744e63f21cd189b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7994,
"upload_time": "2024-03-29T00:54:30",
"upload_time_iso_8601": "2024-03-29T00:54:30.800522Z",
"url": "https://files.pythonhosted.org/packages/5b/32/fb9ff0bef19c05c2782a0e2a25c2b6ab82d49811b1a22135db9007bd815e/rgsucher-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-29 00:54:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "rgsucher",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "rgsucher"
}