Regex: Exact number of symbols and lines [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I would like to use regex in Java to substring text.
The string must be max 140 characters in all ( not counting new line/enter characters) and there might be max 4 lines
I found out how to substring 140 symbols: ^(.|\n|\r){0,140}
My question is how to add limitation for only 4 lines
and exclude new line/enter characters
Thanks for help!

This expression should do what you are looking for:
^([^\r\n]{0,140}(\r?\n|$)){4}
Try it here.

Related

regex match only two group [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I want to receive in example regex match only 17 and 20 (skip 3 match only two match)
Depending on what you want to do, this one can be a good solution
[0-9]{2}(?!$)
It matches the groups of 2 digits not at the end of a line !
You can also try : ([0-9]{2})\s[A-z]+\s([0-9]{2}) if you want only 2 groups

RSA modulus N regular expression [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
This post was edited and submitted for review 7 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I need to make a pattern matching RSA modulus (n) which looks like this:
01sjBnlcardSsWRiEm9i4hZCn0iz12HypdP_1osRvD4O6__tl0qRlE9t1afTXzLDrFaySdQOVd8LGQWi1RixCnb01-7ypxvPDM4yM02haCgD5an9CUSulWUtsiUi01UCgvOYsKEfSBoDVx875G7ypUJx4SN7WnlIDJI2-fWkPwx-hVcDyP6Uzrf9vTsQrzZYAEkIjFcveG_6zwnQtj5K1fIJteZoLeNsTiGwSVJkg6QUkbfVgv5edjE9NTr8Z6jlfJR0q_N9mt3qzRh85ovTNLWoqN99Nbv_t5fq7he6fgM6mnT6PPfaR9auMvtv9kI_659NFKT7BXMD3nV3SjtkSuJFByeiSc5kjrbCGaZB5wgZghYKoQEImrVEotuOXBLVF3-Cw_Jzgcsi7cUfdEH98Ro8_uVJGDMBu0Dbd36d724S-42eh2t9qHor0WosSbCIkuKLVZiiyChRWQk9GelhQ3mSRXmyfVukfMlMpyR0Y3oT4OgQiVtPvONA11PySJpUBItd4xk5tobKE0LaG83bf85syq4PY_jBGVW8Dy-nAmJKcAQ-5UJkNlgzeUK_qbCzjZxrbPwnGm7Pl258a58FtCdFnJYNQjleCE_2YhXX-9iWBS_FycABUdM_tBk0m5NYOZ5JSvx8eQOxUmt7iISa0o24Pu1PNpB2EpANN7KPVZM
or one more example
4VUYy3BrKtcxndUwdAtBE-rqoxVcnceCd2vxvyDxgbNboGGC5cLBion6sM9aAWa1FLCIebN9dgXVnZokzS5KVtRO4BqUAo7u_8yBblSg_PyKqCNao_XGxHaclkuXm5_vFhRNxzk6sA54S2EWOB84Cj7z3EfZaEO2-YGJ7Nkso5ig4IExLnIco688iGTx3EX7sPpGwEfQebMOfDEtmPHpVkJhznad5IzlhEFjZY5tDDZPEIL6jeFbLAoFA6xy9FEp2xt3TDwa_w9cIqGnUVndUzfjXFykRREW88eMMqxuJYeQEAh3pw-huKlCWk78GxO1xoYaVMVeQyYp0r3Pz-FIvPs78KI2pkiT7zmx8viC46Mve2_FYymTGiK1XesoSwqIoANjCeJJV3wEV67nKb5j9uG4Mlhtta5aDbSkV4rYsJbG-A0Tcc5vSEJBwGDeZ_l7McbuWk31vaQcEWoGB3Ktc9Qnl-z4i_N__QcZ7ZEEg2nB797keEHpmuhqqgkUkoetBCxb15_Vfp85j6upACglIodTz60fjf8tZ2gQUwITHNFk2IAX3vcoJuNSblfZwXo-a5FFnY_mcbHmstXuvPu-9ZCC0-UsHX6LTPrt_IJUhKdnLKnvTEWII78VirWcpoYzOBK2EFIs64ELCYnM0szv-Qp4Zcurparp7nkqMpy2O1c
Needed to find it in text like
kty: "RSA",
n: "01sjBnlcardSsWRiEm9i4hZCn0iz12HypdP_1osR..."
or
<n>01sjBnlcardSsWRiEm9i4hZCn0iz12HypdP_1osR...</n>
and so on.
I tried \S{683} but it's too large sample so I need exclude repetition of characters and have their mandatory diversity to escape matching with "aaaaaaaaaa..." or "0000000000..."
Please help if someone has it. Thanks!
If you want to match only when the entire string is exactly 683 characters and contains only valid base64 characters, use:
^[a-zA-Z0-9_\-=]{683}$

Regex pattern to replace characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The program contains text of this type:
A B Ccccc
A Ccccc
ACcccc
ABCcccc
I need only such text to remain:
Ccccc
I wrote a replacement function, but I just can’t pick up a pattern
How to make such a pattern?
No need for regex, nor VBA. It seems you simply are looking for the position of the last upper-case letter and then to extract from there:
Formula in B1 (with Excel O365):
=MID(A1,MAX(SEQUENCE(LEN(A1))*(EXACT(UPPER(MID(A1,SEQUENCE(LEN(A1)),1)),MID(A1,SEQUENCE(LEN(A1)),1)))),LEN(A1))
If you don't have Excel O365:
=MID(A1,MAX(ROW(A1:INDEX(A:A,LEN(A1)))*(EXACT(UPPER(MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1)),MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1)))),LEN(A1))
You probably need to enter as array through: CtrlShiftEnter
If you must go through VBA and regex then a pattern like:
[A-Z][^A-Z]*$

C# Regex Replace string with Ignore specific word [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have File and I want to replace fix character * : ~ with # using regex but, it should not replace(ignore) B~~ word because, it need to remain as it is. Anybody have idea for that?
Input :
ABCHKLJNKL*dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm:skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Output Should be :
ABCHKLJNKL#dskjnsdfkdsmflkmdls
MLKMLKMLKMLKMLKMMML
zlmlkmm#skjnjnskfjnkjsdnkfjnkdjs
B~~KJNNKJNJNKKJNKJNFKKJNJNK
Please provide regex because i want to done with one step.
Thanks
[*:]|(?<!B[~])[~](?![~])
Try this.This should do it.See demo.Replace by #.
https://regex101.com/r/tX2bH4/66

how to get first word after phrase with regex [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How do you find the first word after a string literal via regex?
I.e.
I want to extract "DAQJ7PS" from the line:
ERROR service.PostService - Failed to save post DAQJ7PS
/ERROR service\.PostService - Failed to save post (.+)/
will give you the result in the first capturing group. This can be tuned if you have more specific requirements.