Are regular expressions the best way to match and replace text?

I know well what regular expressions are, so please avoid giving definitions. I'm just looking for an opinion and maybe even advice. I am finishing my studies in the field of computer science soon, and until that moment, the only education I received on regular expressions is the course on the development and development of PL. We have never been educated on the actual application and its use in the programs we write, only when using Regex in fact with a programming language.

I have a question: do I correctly assume that regex is the most powerful matching tool and deals with text? If I am mistaken, what else is there that I should teach myself (as opposed to becoming good with regular expression)? Also, does anyone know of good regular expression plugins for the Eclipse IDE (preferably Galileo). I am looking for something that allows me to test a document and perhaps emphasize what is being done. Thanks

+3
source share
8 answers

It really depends on what it means to be powerful.

RegEx , . - ( ), JavaCC YACC. XML RegEx. RegEx .

, RegEx . , , ""; RegEx '/^Prefix.*/', -RegEx Java 'Str.startsWith("Prefix")'. .

, RegEx . - , , 10; Java :

for(int i = 0; i < Math.min(10, Str.length); i++) {
    char C = Str.charAt(i);
    if ((C < '0') || (C > '0'))
        reutrn false;
}
return true;

RegEx:

static final String CheckRegEx   = "^[0-9]{10,}+"; // So you have it expressed in one place
static final String CheckPattern = Pattern.compile(CheckRegEx);

if (CheckPattern.matches(Str)) {
    // Match
}

RegEx .

, , , , .

RegEx - , .

+4

, . , , , "" (indexOf, substring, contains ..).

, - . , . , , , - ? ? , .

. , , - , . ( - , $ ^ , , .)

+7

, - Eclipse IDE (Galileo ).

Quickrex plugin Eclipse - .

+2

Regex .

, .

Regex - , /, , , . , , .

+2

, . , REs , Perl, Ruby Python. , .

. . substr() index() . , REs .

+2

, . , , , . .

+2

, , , . , regex , ( , ).

- (yacc, bison .). , , perl6, , , ,

+2

Regular expressions are the best tool for specifying matching and replacing strings if they are not. In a log file or text box? Awesome. In an XML or HTML document? Terrible. It really depends on the structure and meaning of the text you are trying to process.

+1
source

Source: https://habr.com/ru/post/1720404/


All Articles