Tumgik
#RegExp
duniailkom · 8 months
Text
Tutorial Cara Penggunaan Regular Expressions Bahasa Java
Untuk pengolahan teks yang lebih rumit, biasanya kita butuh bantuan Regular Expressions atau sering disingkat sebagai Regex. Regex dapat digunakan untuk mencari, mengganti, atau memanipulasi string. Dalam tutorial Duniailkom kali ini kita akan bahas cara penggunaan RegEx dalam bahasa pemrograman Java. Pengertian Regular Expressions Regular expressions (regex) adalah serangkaian karakter yang…
Tumblr media
View On WordPress
1 note · View note
Text
(minors dni)
so it seems that tumblr will now display an overlay that blocks the entire page on certain tag pages which “may contain potentially mature content”
e.g. viewing my own #Art tag page now looks like this—even while logged in with “show me mature content” enabled in my own settings! 🤪
Tumblr media
Mature Content
This blog may contain potentially mature content
View blog
Go to my dashboard
this effectively makes my #Art tag page dashboard-only 🤪
fortunately, a simple CSS tweak removes the overlay, and the posts are all actually still there. scrolling down also successfully loads more posts
just add this rule on a user stylesheet for tumblr:
.community-label-cover__wrapper {    display: none !important; }
I personally use the stylus browser extension for firefox (I’m sure there are other extensions that do the same thing). I added it to a stylesheet (one I’d already made) that’s applied to all URLs on the domain tumblr.com, and it looks like this:
Tumblr media
cool workaround to have to apply to look at my own fucking blog
(I’m putting an unnecessarily finer-grained solution under the readmore, that’s a little more selective about which urls it applies to, but the above should be fine)
if you want to be more selective, you can make a stylesheet that applies only to urls on people’s non-dashboard blogs, not on the dashboard or rest of the site (just in case hiding .community-label-cover__wrapper elements on the dashboard would be a bad thing for whatever reason)
there’s likely a cleaner way to write this (the cleaner way I thought would work didn’t seem to work...) but at any rate, adding a style for URLs matching the regexp https?://(?!www).*\.tumblr.com/.* does the trick: adding it looks like this
Tumblr media
 it doesn’t apply to tumblr.com or www.tumblr.com, but it does apply to e.g.
https://lesbianchemicalplant.tumblr.com
https://lesbianchemicalplant.tumblr.com/tagged/art
https://lesbianchemicalplant.tumblr.com/post/709735214288633856/womensartofwomen-lavender-scarescape-jenna
105 notes · View notes
snarp · 7 months
Text
Dreamed that @nightpool was selling regexps on Etsy (category: fiber arts) and woke up to find my water's cut off
20 notes · View notes
lain-at-the-gay-bar · 2 years
Text
I made a bookmarklet to replace Nick with Sapnap and Clay with Dream!
To use it, make a bookmark with this code in the spot where you would usually put an url
Javascript:void function() { let b=RegExp(/Nick/,"ig"), c="Sapnap", d=RegExp(/Clay/,"ig"), e="Dream", a=document.getElementById("workskin").innerHTML;a=a.replaceAll(b,c); a=a.replaceAll(d,e);document.getElementById("workskin").innerHTML=a }();
and then click on it when your on the tab of whatever fanfic you're reading!
i based it off the code of this y/n replacer :]
6 notes · View notes
the-iron-orchid · 2 years
Text
Rules of Engagement
What with the ongoing Twitter influx, I figure it's a good time to lay down some ground rules around here. I'm generally amiable and open to interaction, but I do have some boundaries and quirks:
🔞 Please do not follow me or interact with my mature-content posts if you are a minor; you will be blocked. This is for everyone's protection!
🚨 I do make a good-faith attempt to tag common triggers (in trigger cw format so that term itself can be regexp filtered). Here is my taglist.
⚠ This is a fandom sideblog! I don't generally follow back unless we have been regularly interacting in some fashion.
😩 I am terrible at keeping up with my dash - if there's something you think I should see, feel free to tag me, DM me, or send it in an ask/submission!
💖 Please do spam like/reblog! It makes me happy to see somebody dig through my archive with their little raccoon hands to discover things they enjoy.
💰 I try to boost commission posts I see within the fandom, and will happily do so if asked nicely.
❔ While I'm generally open to render suggestions, I only take actual render requests during a Renderpalooza. The queue is loooooong.
⛔ I will not ship OCs with anyone under the age of 21, due to the regular presence of BDSM, alcohol, and occasional drug-related themes in my work.
9 notes · View notes
Text
@staff Ladies and gentlebeings of Staff, how hard would it be to block new account creations that regexp match to any number of letters + 3 numbers?? Or just say “that account name is already taken :)” or in some way screw with them. Please, do something about these bot accounts, they are driving us nuts!!!!!
5 notes · View notes
cloudastra1 · 18 days
Text
Tumblr media
Wildcards in MySQL give you the flexibility to perform sophisticated pattern matching in your queries. Whether you’re searching for a part of a string with the % wildcard or targeting specific characters with _, wildcards enhance the capabilities of MySQL's LIKE operator. However, use them wisely to avoid performance issues, especially on large datasets. Combine these with the REGEXP operator when more complex patterns are needed.
By mastering MySQL wildcard characters, you can make your queries more dynamic and efficient, allowing you to extract precisely the data you need from your database.
0 notes
vim-official · 1 month
Text
vimrc, git clone plugins into ~/.vim/bundle
" http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc execute pathogen#infect()
set nocompatible " use vim defaults set scrolloff=3 " keep 3 lines when scrolling set ai " set auto-indenting on for programming
set showcmd " display incomplete commands set nobackup " do not keep a backup file set number " show line numbers set ruler " show the current row and column
set hlsearch " highlight searches set incsearch " do incremental searching set showmatch " jump to matches when entering regexp set ignorecase " ignore case when searching set smartcase " no ignorecase if Uppercase char present set relativenumber
set visualbell t_vb= " turn off error beep/flash "set novisualbell " turn off visual bell
set backspace=indent,eol,start " make that backspace key work the way it should "set runtimepath=$VIMRUNTIME " turn off user scripts, https://github.com/igrigorik/vimgolf/issues/129
set mouse=a set spell let g:lexical#spelllang = ['en_us'] let g:lexical#thesaurus = ['~/.vim/thesaurus/mthesaur.txt',] syntax on " turn syntax highlighting on by default filetype on " detect type of file filetype plugin indent on " load indent file for specific file type colorscheme dracula
set t_RV= " http://bugs.debian.org/608242, http://groups.google.com/group/vim_dev/browse_thread/thread/9770ea844cec3282 let g:ycm_global_ycm_extra_conf = "~/.vim/.ycm_extra_conf.py" set encoding=utf-8 let g:airline_theme='dracula' " let g:airline_theme='violet' let g:airline#extenstions#tabline#enabled = 1 let g:tex_flavor = 'latex' if !exists('g:ycm_semantic_triggers') let g:ycm_semantic_triggers = {} endif au VimEnter * let g:ycm_semantic_triggers.tex=g:vimtex#re#youcompleteme
nnoremap ^[ ^[ let g:UltiSnipsExpandTrigger = '' " use Tab to expand snippets let g:UltiSnipsJumpForwardTrigger = '' " use Tab to move forward through tabstops let g:UltiSnipsJumpBackwardTrigger = '' " use Shift-Tab to move backward through tabstops let g:UltiSnipsSnippetDirectories=[$HOME.'/.vim/UltiSnips'] " using Vim augroup pencil autocmd! autocmd FileType markdown,mkd call pencil#init() \ | call litecorrect#init() \ | call lexical#init() autocmd FileType tex call pencil#init() \ | call litecorrect#init() \ | call lexical#init() autocmd FileType text call pencil#init() \ | call litecorrect#init() \ | call lexical#init() augroup END au FileType markdown,text,tex DittoOn " Turn on Ditto's autocmds nmap di ToggleDitto " Turn Ditto on and off nmap =d DittoNext " Jump to the next word nmap -d DittoPrev " Jump to the previous word nmap +d DittoGood " Ignore the word under the cursor nmap _d DittoBad " Stop ignoring the word under the cursor nmap ]d DittoMore " Show the next matches nmap [d DittoLess " Show the previous matches
let g:pencil#wrapModeDefault = 'soft' " default is 'hard' setlocal fo+=aw nnoremap x ZZ
0 notes
piratesexmachine420 · 3 months
Text
Emperor Palpatine voice: yes, yes, parse that context-sensitive grammar with regexps boy, you know you want to...
0 notes
ao3-userscripts · 3 months
Text
AO3: Highlight Tags
What it does: Highlights tags containing your chosen text in different colors so you can find them faster within a work blurb
Found at: GreasyFork by Fangirlishness
AO3 comes with a lot of text... just like an archive should. But it's easy to overlook certain tags that you'd love to read—or to avoid.
Tumblr media
Install ⇒ AO3: highlight tags V2
This new version lets you define the tag type: characters, relationships, freeforms. For example, you can highlight the relationships featuring your favorite character (in the screenshot above: Bruno), without also highlighting all the freeforms about them (e.g. Parental Bruno Buccellati).
As most scripts that check the tags on works, it cannot guarantee that it highlights all instances correctly, and you have to account for all the ways people might tag for it in the script configuration. For example, if you wish to highlight any "Alternate Universe" type of tag, people might use
the canonical tags that all start with "Alternate Universe", e.g. "Alternate Universe - Modern Setting"
a tag that abbreviates it to "AU", e.g. "modern AU"
a tag that doesn't explicitly state it's an AU because context makes that clear, e.g. "modern setting" in a fantasy fandom
The first two can be covered in the configuration, but the third is hard-to-impossible to catch.
Tumblr media
A couple of things to remember as you're setting up your config:
The script configuration is currently case-sensitive. So "AU" will only highlight tags where it's also capital letters. TBH I highly recommend switching it to case-insensitive by adding the "i" in front of the "g" at the end of the line so the code becomes: var pattern = new RegExp(key, "ig")
Tumblr media
The script tries to find any tag that contains the text you configured. That can even be in the middle of the word: configuring "au" would higlight tags including the word author, trauma, etc.
If you know a little bit of RegEx, you've just become so much more powerful! As an example, \b is the RegEx "word boundary" metacharacter, and to make it work in the script, its backslash needs to be escaped with another backslash. To highlight tags including the word "au" like in highschool!au but not in trauma, you can configure "\\bau\\b".
Tumblr media
Because RegEx is supported in this script, some characters need to be "escaped" by preceding them with a backslash, so that the highlighting takes them literally within a tag. That includes quotes ", pipes |, parenthesis (), square brackets [], slashes /, or dots... and the backslash of all RegEx metacharacters.
If you want to check for relationships, the tags might include them in either order. You can set up multiple lines in the configuration. With RegEx, you can also do it in a single line. Configure "relationships!(Geralt.*\/.*Jaskier)|(Jaskier.*\/.*Geralt)" and it'll highlight either order of them in a romantic relationship. Now, Jaskier is sometimes called Dandelion, so we could go one step further and make the logic check for either of his names: "relationships!(Geralt.*\/.*(Jaskier|Dandelion))|((Jaskier|Dandelion).*\/.*Geralt)"
If you use and enjoy this userscript, also consider giving its author some feedback!
0 notes
suncloudvn · 3 months
Text
Lệnh Sed trong Linux - Hướng dẫn sử dụng đơn giản, chi tiết
Tumblr media
Trong quản trị hệ thống và lập trình, việc xử lý và chỉnh sửa văn bản là một công việc thường xuyên và quan trọng. Một trong những công cụ mạnh mẽ và phổ biến nhất để thực hiện nhiệm vụ này trên các hệ thống Unix/Linux là lệnh sed. Bài viết này sẽ giới thiệu chi tiết về lệnh sed, cách cài đặt và sử dụng nó một cách dễ dàng và hiệu quả.
I. Lệnh sed là gì?
Lệnh sed là viết tắt của “stream editor”, là một công cụ dòng lệnh được sử dụng để chỉnh sửa văn bản trực tiếp từ dòng dữ liệu (streams) hoặc từ file. Sed có khả năng thực hiện các thao tác chỉnh sửa văn bản như tìm kiếm, thay thế, chèn, xóa, và nhiều thao tác khác mà không cần mở file trong một trình soạn thảo văn bản.
Lệnh sed xuất hiện từ những năm 1970, nó được phát triển bởi Lee E. McMahon, và đã trở thành một phần quan trọng trong bộ công cụ Unix truyền thống.
II. Cơ chế hoạt động của lệnh sed
Sed sẽ xử lý văn bản theo dòng (line-by-line), cho phép người dùng áp dụng các lệnh chỉnh sửa trên từng dòng văn bản. Nó có thể hoạt động trong hai chế độ chính:
Script mode: Thực thi một tập hợp các lệnh từ file bash-scripts
Command line mode: Thực thi các lệnh trực tiếp từ dòng lệnh
Mặc dù bản thân sed cực kỳ linh hoạt nhưng nó thường được sử dụng kết hợp với các lệnh Linux khác như awk để xử lý văn bản, grep để tìm kiếm mẫu và cat để hiển thị nội dung file. Cùng với nhau, những công cụ này tạo thành một bộ công cụ mạnh mẽ để xử lý văn bản trong môi trường Linux.
III. Hướng dẫn sử dụng lệnh sed trong Linux
1. Cài đặt sed trên hệ thống
Một số hệ thống đã được tích hợp sẵn lệnh sed trong bộ máy, tuy nhiên một số lại không có. Để biết được máy đã có thể sử dụng lệnh sed hay chưa, chúng ta sử dụng câu lệnh sau để kiểm tra:
sed --version 
Nếu máy chưa có bạn có thể thực hiện cài đặt gói của lệnh sed bằng cách sử dụng một số câu lệnh sau:
# Nếu hệ điều hành của bạn là Ubuntu
sudo apt-get install sed
# Nếu hệ điều hành của bạn là CentOS
sudo yum install sed
# Nếu hệ điều hành của bạn là macOS
brew install gnu-sed
2. Cú pháp và các tùy chọn của lệnh sed trong Linux
2.1. Cú pháp cơ bản của lệnh sed trong Linux
Cú pháp tổng quát của lệnh sed:
sed [OPTIONS] ‘scripts’ filename
Trong đó:
OPTIONS: là các tùy chọn của lệnh sed
‘scripts’: là các lệnh sed
filename: là file văn bản cần được xử lý
2.2. Các tùy chọn của lệnh sed và ví dụ
Một số tùy chọn phổ biến:
-e script: Chỉ định lệnh hoặc tập hợp các lệnh sed để thực thi. Tùy chọn này có thể sử dụng nhiều lần để thực thi nhiều lệnh.
# Sử dụng 2 lệnh cùng lúc
sed -e 's/foo/bar/' -e 's/baz/qux/' file.txt
-f script-file: Đọc các lệnh từ file script được chỉ định thay vì từ dòng lệnh. Tùy chọn này cũng có thể sử dụng nhiều lần để đọc từ nhiều file script.
# Đọc lệnh từ file script.sed và thực hiện trên file.txt
sed -f script.sed file.txt
-i[SUFFIX]: Chỉnh sửa trực tiếp trên file gốc. Có thể chỉ định thêm một hậu tố để tạo bản sao lưu của file gốc. Ví dụ: -i.bak sẽ tạo file sao lưu với đuôi .bak.
# Thay thế foo = bar trong file.txt, tạo ra 1 file sao lưu
sed -i.bak 's/foo/bar/' file.txt
-n: Không tự động in ra dòng đầu vào. Tùy chọn này thường được dùng kèm với lệnh p (print) để chỉ in ra những dòng thỏa mãn điều kiện.
# Chỉ in ra những dòng được thay đổi
sed -n 's/foo/bar/p' file.txt
Một số tùy chọn khác:
-r hoặc --regexp-extended: Sử dụng cú pháp biểu thức chính quy mở rộng (Extended Regular Expressions, ERE).
-s: Xử lý mỗi file đầu vào riêng biệt. Tùy chọn này rất hữu ích khi làm việc với nhiều file.
-u: Chạy chế độ không đệm (unbuffered). Tùy chọn này chủ yếu được sử dụng trên các hệ thống có vấn đề với đệm đầu vào/đầu ra.
--help: Hiển thị trợ giúp và thoát. Cung cấp một danh sách các tùy chọn và cú pháp lệnh sed.
--version: Hiển thị thông tin phiên bản của sed và thoát.
3. Các lệnh cơ bản của lệnh sed trong Linux
3.1. Lệnh thay thế (s)
Cú pháp của lệnh:
sed 's/old-text/new-text' filename
Trong đó:
- s: Bắt đầu lệnh
- old-text: văn bản cũ
- new-text: văn bản mới
- filename: tên file được áp dụng
Ví dụ:
# Thay thế old = new trong test.txt
sed ‘s/old/new’ test.txt
Có thể dùng kèm các cờ như:
`g`: Thay thế tất cả các lần xuất hiện trong một dòng.
`p`: In dòng chứa chuỗi được thay thế.
`w file`: Ghi dòng chứa chuỗi được thay thế vào file.
3.2. Lệnh xóa dòng (d)
Cú pháp của lệnh:
sed 'Nd' filename
Trong đó:
- N: là vị trí dòng cần xóa
- d: là lệnh xóa
- filename: tên file được áp dụng
Ví dụ:
# Xóa dòng thứ 2 trong file test.txt
sed ‘2d’ test.txt
3.3. Lệnh chèn (i) và lệnh thêm (a)
Cú pháp của lệnh chèn:
sed 'Ni\new-line' filename
Trong đó:
- N: là vị trí dòng cần chèn
- i: là lệnh chèn
- new-line: là nội dungdòng muốn chèn
- filename: tên file được áp dụng
Ví dụ lệnh chèn:
# Chèn dòng “testi” lên trước dòng thứ 2 của file test.txt 
sed ‘2i\testi’ test.txt
Cú pháp của lệnh thêm:
sed 'Na\new-line' filename
Trong đó:
- N: là vị trí dòng cần thêm
- a: là lệnh thêm
- new-line: là nội dung dòng muốn thêm
- filename: tên file được áp dụng
Ví dụ lệnh thêm:
# Thêm dòng “testa” vào sau dòng thứ 2 của file test.txt 
sed ‘2a\testa’ test.txt
3.4. Lệnh thay thế dòng
Cú pháp của lệnh:
sed 'Nc\new-line' filename
Trong đó:
- N: là vị trí dòng cần thay thế
- c: là lệnh thay thế
- new-line: Nội dung thay thế
- filename: tên file được áp dụng
Ví dụ:
# Thay thế dòng thứ 3 bằng “testc” trong file test.txt
sed ‘3c\testc’ test.txt
3.4. Một số lệnh khác
- p: In dòng
- y/source/dest/: Chuyển đổi các kí tự từ source sang dest
- q: Thoát ngay lập tức
- =: In số dòng hiện tại
- !: Đảo ngược lệnh, tức là thực hiện lệnh trên những dòng không khớp với biểu thức đã cho
4. Một số ví dụ nâng cao
Chỉnh sửa nhiều dòng cùng một lúc:
# Thay thế old = new trong các dòng từ 3 - 5 trong file test.txt
sed '3,5s/old/new/g' test.txt
Áp dụng các điều kiện với lệnh sed:
# Thay thế old = new trong những dòng chứa “change” trong file test.txt
sed '/change/s/old/new/' inputfile
Kết hợp sed với grep:
# Tìm các dòng chứa "change" và thay thế "old" bằng "new" trong test.txt
grep 'change' test.txt| sed 's/old/new/g'
Tổng kết
Lệnh sed là một phần không thể thiếu trong bộ công cụ của bất kỳ quản trị viên hệ thống hoặc lập trình viên nào làm việc trên môi trường Unix/Linux. Khả năng xử lý mạnh mẽ, cú pháp linh hoạt và tính năng đa dạng của sed làm cho nó trở thành một công cụ quý giá cho mọi tác vụ xử lý và chỉnh sửa văn bản. Bằng cách nắm vững Sed, người dùng có thể đơn giản hóa và tự động hóa nhiều công việc phức tạp, nâng cao hiệu quả công việc và đạt được kết quả chính xác hơn trong thời gian ngắn hơn.
Nguồn: https://suncloud.vn/lenh-sed-trong-linux
0 notes
hackernewsrobot · 4 months
Text
Regular Expression Matching with a Trigram Index (2012)
https://swtch.com/~rsc/regexp/regexp4.html
0 notes
snarp · 7 months
Text
Stop writing regexps and eat one piece of bread
4 notes · View notes
learning-path · 5 months
Text
Python Regular Expression
Unleash the power of Python's re module with these regex examples! From checking website URLs to extracting data and even text manipulation, this tutorial has got you covered. Level up your text processing skills with Python at @p4n.in #Python #Regex #
Introduction to the re Module Regular expressions, often abbreviated as regex or regexp, are sequences of characters that define a search pattern. They are widely used in text processing tasks such as pattern matching, search and replace operations, and validation of input data. In Python, the re module provides support for working with regular expressions. re — Regular Expression…
View On WordPress
0 notes
holyjak · 6 months
Text
Great tips for making RegExp more readable: 1) Add the (?x) so that whitespace are ignored (such as newlines -> can break over multiple lines) and you can include line comments with # whatever.... 2) Use named capture groups for self-documentatiion via ?<label>, as in (?<id>\d+). (Beware: you then also need to use those to access the matched values, as in (.group matcher "id"). The follow-up blog shows how to make extracting all groups at once easier on Java 20+.)
0 notes
quanyails · 7 months
Text
Multiple String Replace
A small programming exercise:
Given a string s and a map of replacements r with strings a1, b1, … z1 and a2, b2, … z2, return a string where all instances of a1, b1, … z1 in s are replaced by a2, b2, … z2.
Assume all strings are alphanumeric.
Assume no two inputs a1, b1, … z1 overlap.
You may use library builtins.
Example 1
Input: s = "helloworld", r = {"hello", "hi"} Output: "hiworld"
Example 2
Input: s = "abc123", r = {"ab": "c1", "c1": "23", "23": "ab"} Output: "c123ab"
Sample solution below the cut.
Sample solution (JavaScript)
const solution = (s, r) => { const pattern = new RegExp(Object.keys(r).join("|"), "g"); return s.replaceAll(pattern, match => r[match]); }
0 notes