Tuesday, June 4, 2013

How to use regular expressions in Notepad++ (tutorial)

In case you have the plugins installed, try Ctrl+R or in the TextFX -> TextFX Quick -> Find/Replace to get a sophisticated dialogue including a drop down for regular expressions and multi line search/replace.
This tutorial was based on an earlier, far more limited regular expression syntax. The examples are still the same at the date of writing, they require additions or upgrading to the new ways.
Notepad++ regular expressions use the standard PCRE (Perl) syntax, only departing from it in very minor ways. Complete documentation on the precise implementation is to be found the implementer's website.
Another great tutorial is provided online at http://www.regular-expressions.info .
A french Sourceforge user, guy038, made a tutorial available in the French language. This is hosted at ici in a variety of formats.

Contents

[hide]
In a regular expression (shortened into regex throughout), special characters interpreted are:

Single-character matches

.\c
Matches any character. If you check the box which says ". matches newline", the dot will indeed do that, enabling the "any" character to run over multiple lines. With the option unchecked, then . will only match characters within a line, and not the line ending characters (\r and \n)
\X
Matches a single non-combining characer followed by any number of combining characters. This is useful if you have a Unicode encoded text with accents as separate, combining characters.
\Г
This allows you to use a character Г that would otherwise have a special meaning. For example, \[ would be interpreted as [ and not as the start of a character set. Adding the backslash (this is called escaping) works the other way round, as it makes special a character that otherwise isn't. For instance, \d stands for "a digit", while "d" is just an ordinary letter.
Non ASCII characters
\xnn
Specify a single chracter with code nn. What this stands for depends on the text encoding. For instance, \xE9 may match an é or a θ depending on the code page in an ANSI encoded document.
\x{nnnn}
Like above, but matches a full 16-bit Unicode character. If the document is ANSI encoded, this construct is invalid.
\Onnn
A single byte character whose code in octal is nnn.
[[.collating sequence.]]
The character the collating sequence stands for. For instance, in Spanish, "ch" is a single letter, though it is written using two characters. That letter would be represented as [[.ch.]]. This trick also works with symbolic names of control characters, like [[.BEL.]] for the character of code 0x07. See also the discussion on character ranges.
Control characters
\a
The BEL control character 0x07 (alarm).
\b
The BS control character 0x08 (backspace). This is only allowed inside a character class definition. Otherwise, this means "a word boundary".
\e
The ESC control character 0x1B.
\f
The FF control character 0x0C (form feed).
\n
The LF control character 0x0A (line feed). This is the regular end of line under Unix systems.
\r
The CR control character 0x0D (carriage return). This is part of the DOS/Windows end of line sequence CR-LF, and was the EOL character on Mac 9 and earlier. OSX and later versions use \n.
\R
Any newline character.
\t
The TAB control character 0x09 (tab, or hard tab, horizontal tab).
\Ccharacter
The control character obtained from character by stripping all but its 6 lowest order bits. For instance, \C1, \CA and \Ca all stand for the SOH control character 0x01.

Ranges or kinds of characters

[...]
This indicates a set of characters, for example, [abc] means any of the characters a, b or c. You can also use ranges, for example [a-z] for any lower case character. You can use a collating sequence in character ranges, like in [[.ch.]-[.ll.]] (these are collating sequence in Spanish).
[^...]
The complement of the characters in the set. For example, [^A-Za-z] means any character except an alphabetic character. Care should be taken with a complement list, as regular expressions are always multi-line, and hence [^ABC]* will match until the first A,B or C (or a, b or c if match case is off), including any newline characters. To confine the search to a single line, include the newline characters in the exception list, e.g. [^ABC\r\n].
[[:name:]]
The whole character class named name. Most of the time, there is a single letter escape sequence for them - see below.
Recognised classes are:
  • alnum : ASCII letters and digits
  • alpha : ASCII letters
  • blank : spacing which is not a line terminator
  • cntrl : control characters
  • d , digit : decimal digits
  • graph : graphical character
  • l , lower : lowercase letters
  • print : printable characters
  • punct : punctuation characters: , " ' ? ! ; : # $ % & ( ) * + - / < > = @ [ ] \ ^ _ { } | ~
  • s , space : whitespace
  • u , upper : uppercase letters
  • unicode : any character with code point above 255
  • w , word : word character
  • xdigit : hexadecimal digits
\pshort name,\p{name}
Same as [[:name:]]. For instance, \pd and \p{digit} both stand for a digit, \d.
\Pshort name,\P{name]
Same as [^[:name:]] (not belonging to the class name).
Note that Unicode categories like in \p{Sc} or \p{Currency_Symbol}, they are flagged as an invalid regex in v6.3.2. This is because support would draw a large library in, which would have other uses.
\d
A digit in the 0-9 range, same as [[:digit:]].
\D
Not a digit. Same as [^[:digit]].
\l
A lowercase letter. Same as [a-z] or [[:lower:]].
NOTE: this will fall back on "a word character" if the "Match case" search option is off.
\L
Not a lower case letter. See note above.
\u
An uppercase letter. Same as [[:uper:]]. See note about lower case letters.
\U
Not an uppercase letter. Same note applies.
\w
A word character, which is a letter, digit or underscore. This appears not to depend on what the Scintilla component considers as word characters. Same as [[:word:]].
\W
Not a word character. Same as :alnum: with the addition of the underscore.
\s
A spacing character: space, EOLs and tabs count. Same as [[:space:]].
\S
Not a space.
\h
Horizontal spacing. This only matches space, tab and line feed.
\H
Not horizontal whitespace.
\v
Vertical whitespace. This encompasses the The VT, FF and CR control characters: 0x0B (vertical tab), 0x0D (carriage return) and 0x0C (form feed).
\V
Not vertical whitespace.
[[=primary key=]]
All characters that differ from primary key by case, accent or similar alteration only. For example [[=a=]] matches any of the characters: a, À, Á, Â, Ã, Ä, Å, A, à, á, â, ã, ä and å.

Multiplying operators

+
This matches 1 or more instances of the previous character, as many as it can. For example, Sa+m matches Sam, Saam, Saaam, and so on. [aeiou]+ matches consecutive strings of vowels.
*
This matches 0 or more instances of the previous character, as many as it can. For example, Sa*m matches Sm, Sam, Saam, and so on.
?
Zero or one of the last character. Thus Sa?m matches Sm and Sam, but not Saam.
*?
Zero or more of the previous group, but minimally: the shortest matching string, rather than the longest string as with the "greedy" * operator. Thus, m.*?o applied to the text margin-bottom: 0; will match margin-bo, whereas m.*o will match margin-botto.
+?
One or more of the previous group, but minimally.
{n}
Matches n copies of the element it applies to.
{n,}
Matches n' or more copies of the element it applies to.
{m,n}
Matches m to n copies of the element it applies to, as much it can.
{n,}?,{m,n}?
Like the above, but match as few copies as they can. Compare with *? and friends.
*+,?+,++,{n,}+,{m,n}+
These so called "possessive" variants of greedy repeat marks do not backtrack. This allows failures to be reported much earlier, which can boost performance significantly. But they will eliminate matches that would require backtracking to be found.
Example: matching ".*" against "abc"x will find "abc", because
  • " then abc"x then $ fails
  • " then abc" then x fails
  • " then abc then " succeeds.
However, matching "*+" against "abc"x will fail, because the possessive repeat factor prevented backtracking.

Anchors

Anchors match a position in the line, rather than a particular character.
^
This matches the start of a line (except when used inside a set, see above).
$
This matches the end of a line.
\<
This matches the start of a word using Scintilla's definitions of words.
\>
This matches the end of a word using Scintilla's definition of words.
\b
Matches either the start or end of a word.
\B
Not a word boundary.
\A\'
The start of the matching string.
\z\`
The end of the matching string.
\Z
Matches like \z with an optional sequence of newlines before it. This is equivalent to (?=\v*\z), which departs from the traditional Perl meaning for this escape.

Groups

(...)
<Parentheses mark a subset of the regular expression. The string matched by the contents of the parentheses ( ) can be re-used as a backreference or as part of a replace operation; see Substitutions, below.
Groups may be nested.
(?<some name>...), (?'some name'...),(?(some name)...)
Names this group some name.
\gn , \g{n}
The n-th subexpression, aka parenthesised group. Uing the second form has some small benefits, like n being more than 9, or disambiguating when n might be followed by digits. When n' is negative, groups are counted backwards, so that \g-2 is the second last matched group.
\g{something},\k<something>
The string matching the subexpression named something.
\digit
Backreference: \1 matches an additional occurence of a text matched by an earlier part of the regex. Example: This regular expression: ([Cc][Aa][Ss][Ee]).*\1 would match a line such as Case matches Case but not Case doesn't match cASE. A regex can have multiple subgroups, so \2, \3, etc can be used to match others (numbers advance left to right with the opening parenthesis of the group). So \n is a synonym for \gn, but doesn't support the extension syntax for the latter.

Readability enhancements

(:...)
A grouping construct that doesn't count as a subexpression, just grouping things for easier reading of the regex.
(?#...)
Comments. The whole group is for humans only and will be ignored in matching text.
Using the x flag modifier (see section below) is also a good way to improve readability in complex regular expressions.

Search modifiers

The following constructs control how matches condition other matches, or otherwise alter the way search is performed. For those readers familiar with Perl, \G is not supported.
\Q
Starts verbatim mode (Perl calls it "quoted"). In this mode, all characters are treated as-is, the only exception being the \E end verbatim mode sequence.
\E
Ends verbatim mode. Ths, "\Q\*+\Ea+" matches "\*+aaaa".
(?:flags-not-flags ...), (?:flags-not-flags:...)
Applies flags and not-flags to search inside the parentheses. Such a construct may have flags and may have not-flags - if it has neither, it is just a non-marking group, which is just a readability enhancer. The following flags are known:
   i : case insensitive (default: off)
   m : ^ and $ match embedded newlines (default: as per ". matches newline")
    s: dot matches newline (default: as per ". matches newline")
    x: Ignore unescaped whitespace in regex (default: off)
(?|expression using the alternation | operator)
If an alternation expression has subexpressions in some of its alternatives, you may want the subexpression counter not to be altered by what is in the other branches of the alternation. This construct will just do that.
For example, you get the following subexpressioncounter values:
# before  ---------------branch-reset----------- after
/ ( a )  (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x
# 1            2         2  3        2     3     4
Without the construct, (p(q)r) would be group #3, and (t) group #5. With the constuct, they both report as group #2.

Control flow

Normally, a regular expression parses from left to right linerly. But you may need to change this behaviour.
|
The alternation operator, which allows matching either of a number of options, like in : one|two|three to match either of "one", "two" or "three". Matches are attempted from left to right. Use (?:) to match an empty string in such a construct.
(?n), (?signed-n)
Refers to subexpression #n. When a sign is present, go to the signed-n-th expression.
(?0), (?R)
Backtrack to start of pattern.
(?&name)
Backtrack to subexpression named name.
(?assertionyes-pattern|no-pattern)
Mathes yes-pattern if assertion is true, and no-pattern otherwise if provided. Supported assertions are:
  • (?=assert) (positive lookahead)
  • (?!assert) (negative lookahead)
  • (?(R)) (true if inside a recursion)
  • (?(Rn) (true if in a recursion to subexpression numbered n
PCRE doesn't treat recursion expressions like Perl does:
In PCRE (like Python, but unlike Perl), a recursive subpattern call  is
always treated as an atomic group. That is, once it has matched some of
the subject string, it is never re-entered, even if it contains untried
alternatives  and  there  is a subsequent matching failure.
\K
Resets matched text at this point. For instance, matching "foo\Kbar" will not match bar". It will match "foobar", but will pretend that only "bar" matches. Useful when you wish to replace only the tail of a matched subject and groups are clumsy to formulate.

Assertions

These special groups consume no characters. Their succesful matching counts, but when they are done, matching starts over where it left.
(?=pattern
If pattern matches, backtrack to start of pattern. This allows using logical AND for combining regexes.
For instance,
(?=.*[[:lower:]])(?=.*[[:upper:]]).{6,}
tries finding a lowercase letter anywhere. On success it backtracks and searches for an uppercase letter. On yet another success, it checks whether the subject has at least 6 characters.
'"q(?=u)i" doesn't match "quit", because, as matching 'u' consumes 0 characters, matching "i" in the pattern fails at "u" i the subject.
(?!pattern
Matches if pattern didn't match.
(?<=pattern)
Asserts that pattern matches before some token.
(?<pattern)
Asserts that pattern does not match before some token.
NOTE: pattern has to be of fixed length, so that the regex engine knows where to test the assertion.
(?>pattern)
Match pattern independently of surrounding patterns, and don't backtrack into it. Failure to match will caus the whole subject not to match.

Substitutions

\a,\e,\f,\n,\r,\t,\v
The corresponding control character, respectively BEL, ESC, FF, LF, CR, TAB and VT.
\Ccharacter", \xnn,\x{nnnn</i>}
Like in search patterns, respectively the control character with the same low order bits, the character with code 'nn and the character with code nnnn (requires Unicode encoding).
\l
Causes next character to output in lowercase
\L
Causes next characters to be output in lowercase, until a \E is found.
\u
Causes next character to output in uppercase
\U
Causes next characters to be output in uppercase, until a \E is found.
\E
Puts an end to forced case mode initiated by \L or \U.
$&, $MATCH, ${^MATCH}
The whole matched text.
$`, $PREMATCH, ${^PREMATCH}
The text between the previous and current match, or the text before the match if this is the first one.
$", $POSTMATCH, ${$POSTMATCH}
Everything that follows current match.
$LAST_SUBMATCH_RESULT, $^N
Returns what the last matching subexpression matched.
$+, $LAST_PAREN_MATCH
Returns what matched the last subexpression in the pattern.
$$
Returns $.
$n, ${n}, \n
Returns what matched the subexpression numbered n. Negative indices are not alowed.
$+{name}
Returns what matched subexpression named name.

Zero length matches

While, in normal or extended mode, there would be no point in looking for text of length 0, this can very normally happen with regula expressions. For instance, to add something at the beginning of a line, you'll search for "^" and replace with whatever is to be added.
Notepad++ would select the match, bt there is no sensible way to select a stretch zero character long. Whe this happens, a tooltip very similar to function call tips is displayed instea, with a caret pointing upwards to the empty match.
Image:Zero.png
A match was found at the first column of line 5.


Examples

These examples come from an earlier version of this page: Notepad++ RegExp Help, by Author : Georg Dembowski


Add more examples using advanced features of PCRE


IMPORTANT
  • You have to check the box "regular expression" in search & replace dialog
  • When copying the strings out of here, pay close attention not to have additional spaces in front of them! Then the RegExp will not work!

Example 0

How to replace/delete full lines according to a regex pattern? Let's say you wish to delete all the lines in a file that contain the word "unused", without leaving blank lines in their stead. This means you need to locate the line, remove it all, and additionally remove its terminating newline.
So, you'd want to do this:: Find: ^.*?unused.*?$\R Replace with: nothing, not even a space The regular expression appears to always work is to be read like this:
  • assert the start of a line
  • match some characters, stopping as early as required for the expression to match
  • the string you search in the file, "unused"
  • more characters, again stopping at the earliest necessary for the expression to match
  • assert line ends
  • A newline character or sequence
Remember that .* gobbles everything to the end of line if ". matches newline" is off, and to the end of file if the option is on!
Well, why is appears above in bold letters? Because this expression assumes each line ends with an end of line sequence. This is almost always true, and may fail for the last line in the file. It won't match and won't be deleted.
But the remedy is fairly simle: we translate in regex parlance that the newline should match if it is there. So the correct expression actually is:
^.*?unused.*?$\R?

Example 1

You use a MediaWiki (e.g. Wikipedia, Wikitravel) and want to make all headings one "level higher", so a H2 becomes a H1 etc.
    • Search ^=(=)
    • Replace with \1
    • Click "Replace all"

      You do this to find all headings2...9 (two equal sign characters are required) which begin at line beginning (^) and to replace the two equal sign characters by only the last of the two, so eleminating one and having one remaining.
    • Search =(=)$
    • Replace with \1
    • Click "Replace all"

      You do this to find all headings2...9 (two equal sign characters are required) which end at line ending ($) and to replace the two equal sign characters by only the last of the two, so eleminating one and having one remaining.
== title == became = title =, you're done :-)

Example 2

You have a document with a lot of dates, which are in German date format (dd.mm.yy) and you'd like to transform them to sortable format (yy-mm-dd). Don't be afraid by the length of the search term – it's long, but consiting of pretty easy and short parts.
Do the following:
  • Search ([^0-9])([0123][0-9])\.([01][0-9])\.([0-9][0-9])([^0-9])
  • Replace with \1\4-\3-\2\5
  • Click "Replace all"
You do this to fetch
  • the day, whose first number can only be 0, 1, 2 or 3
  • the month, whose first number can only be 0 or 1
  • but only if the separator is . and not 'any character' ( . versus \. )
  • but only if no numbers are sourrounding the date, as then it might be an IP address instead of a date
and to write all of this in the opposite order, except for the surroundings. Pay attention: Whatever SEARCH matches will be deleted and only replaced by the stuff in the REPLACE field, thus it is mandatory to have the surroundings in the REPLACE field as well!
Outcome:
  • 31.12.97 became 97-12-31
  • 14.08.05 became 05-08-14
  • the IP address 14.13.14.14 did not change
You're done :-)

Example 3

You have printed in windows a file list using dir /b/s >filelist.txt to the file filelist.txt and want to make local URLs out of them.
  1. Open filelist.txt with Notepad++
    • Search \\
    • Replace with /
    • Click "Replace all" to change windows path separator char \ into URL path separator char /
    • Search ^(.*)$
    • Replace with file:///\1
    • Click "Replace all" to add file:/// in the beginning of all lines
According on your requirements, preceed to escape some characters like space to %20 etc. C:\!\aktuell.csv became file:///C:/!/aktuell.csv
You're done :-)

Example 4

Another Search Replace Example
[Data]
AS AF AFG 004 Afghanistan
EU AX ALA 248 Åland Islands
EU AL ALB 008 Albania, People's Socialist Republic of
AF DZ DZA 012 Algeria, People's Democratic Republic of
OC AS ASM 016 American Samoa
EU AD AND 020 Andorra, Principality of
AF AO AGO 024 Angola, Republic of
NA AI AIA 660 Anguilla
AN AQ ATA 010 Antarctica (the territory South of 60 deg S)
NA AG ATG 028 Antigua and Barbuda
SA AR ARG 032 Argentina, Argentine Republic
AS AM ARM 051 Armenia
NA AW ABW 533 Aruba
OC AU AUS 036 Australia, Commonwealth of
  • Search for: ([A-Z]+) ([A-Z]+) ([A-Z]+) ([0-9]+) (.*)
  • Replace with: \1,\2,\3,\4,\5
  • Hit "Replace All"
Final Data:
AS,AF,AFG,004,Afghanistan
EU,AX,ALA,248,Åland Islands
EU,AL,ALB,008,Albania, People's Socialist Republic of
AF,DZ,DZA,012,Algeria, People's Democratic Republic of
OC,AS,ASM,016,American Samoa
EU,AD,AND,020,Andorra, Principality of
AF,AO,AGO,024,Angola, Republic of
NA,AI,AIA,660,Anguilla
AN,AQ,ATA,010,Antarctica (the territory South of 60 deg S)
NA,AG,ATG,028,Antigua and Barbuda
SA,AR,ARG,032,Argentina, Argentine Republic
AS,AM,ARM,051,Armenia
NA,AW,ABW,533,Aruba
OC,AU,AUS,036,Australia, Commonwealth of

Example 5

How to recognize a balanced expression, in mathematics or in programming?
Let's first explicitly describe what we wish to match. An expression is balanced if and only if all areas delineatd by parentheses contain a balanced expression. Like in: 1+f(x+g())-h(2).
This leads to define the following kinds of groups: balanced ::= no_paren paren ... no_paren
no_paren = [^()]* -- a possibly empty group of characters without a single parenthesis
paren ::= ( balanced )
Can we represent this as a regex? We cannot as-is.
The first hurdle is that there is no primitive construct to represent an alternating sequence of tokens. A common trick then is to represent the sequence as a repetition of the repeating pattern - here, no_paren followed by paren -, with any odd stuff at the end added.
So we have a more manageable, although slightly more complex, representation:
balanced ::= simple* no_paren
simple ::= no_paren paren
no_paren ::= [^()]*
paren = ( balanced )

A second hurdle is that parentheses are not ordinary characters. That's ok, we'll escape them as \( and \) respectively.
The third one is more interesting. How do we represent the whole of an expression inside a nested sub-expression? This smacks of recursion. PCRE has recursion. The simplest form of it is tgoing back to the start of the search pattern - not the searched text! - and doing it again. It writes as (?R). You remember seeing this one in the main list, right?
So:
  • we know how to match a no_paren. It will be nicer to give it an explicit name. This we'll do in the embelishments section below.
  • we jusrtr discovered how to write a paren: \((?R)\)
This gives us the following hard to read, but correct regex:
([^()]*\((?R)\))*[^()]*
Try it, it works. But it is about as hard to decrypt as a badly indented piece of code without a comment and with unpromising, unclear identifiers. This is only one of the reasons why old Perl earned itself the rare qualifier of "write-only language".
Embellishments
First of all, let's add some spacing so that we can identify the components of the regex. Spacing can be added using the x modifier flag, which is off by default.
So we can write something more legible:
(?x:  ([^ ( ) ]* \( (?R) \) )* [^()]* )
Now let's add some commenting
(?x:  ([^ ( ) ]* \( (?# The next group means "start matching the 
beginning of the regex")(?R) \) )* [^()]* ) 
Source: http://sourceforge.net 

Using auto-translatables for number format conversion in MemoQ

Among other things, the auto-translatables function in memoQ can be used to convert numbers from one language format to another. For example, English uses the comma as a thousands separator, and the full stop as a decimal separator. Italian uses them the opposite way. With the proper auto-translatable rules set, memoQ will provide the "localized" version of numbers found in the source segment. These localized numbers are shown in the Translation results list. These auto-translated hits can be inserted quickly into the translation just like hits from translation memories or term bases. Auto-translatables are also used by the fragment assembly function.
Auto-translatables can be set at the project level (in the settings page of the project) or the global level for every project with the same source and target languages (in Tools menu > Options > Auto-translatables).
English to Danish/Dutch/Croatian/German/Romanian/Slovenian/Spanish
Below are the rules to enter for a project translated from English to the above (and possibly other) languages. It will localize numbers containing decimal separators or thousands separators (not both). The rules need to be entered exactly as below in the exact same order to ensure that they work correctly. For information on entering auto-translatable rules, see the memoQ help topics under Language specific settings > Auto-translations.
Rule 1 (changes 1.234 to 1,234)
Auto-translatable rule:
(\d+)\.(\d+)
Replace order rule:
$1,$2
Explanation: If a sequence of digits is followed by a full stop and another sequence of digits, this rule will replace the full stop with a comma.
Rule 2 (changes 12,345,678 to 12.345.678)
Auto-translatable rule:
([\d]{1,3}),?(\d\d\d),?(\d\d\d)
Replace order rule:
$1.$2.$3
Explanation: If a sequence consisting of 1 to 3 digits is followed by a comma, which is followed by three digits, another comma and thrre digits again, the rule will replace the commas with full stops.
Rule 3 (changes 12,345 to 12.345)
Auto-translatable rule:
([\d]{2,3}),?(\d\d\d)
Replace order rule:
$1.$2
Explanation: If a sequence consisting of 2 to 3 digits is followed by a comma, which is followed by three digits, the rule will replace the comma with a full stop.
Source: http://kilgray.com

Regular expressions in MemoQ

Regular expressions are a powerful means for finding character sequences in text. In memoQ, they are used to define segmentation rules and auto-translation rules.
Finding character sequences is a familiar task to everyone who has used a word processor or text editor before. The Find or Search dialog serves this purpose – if you search for ‘cat’, your editor will highlight words (or parts of words) such as ‘cat’, ‘cats’, or even ‘sophisiticated’.
Regular expressions, however, provide a lot more freedom to tell the computer what you are looking for. You can identify sequences such as a letter ‘a’, followed by two or three letters ‘c’; a number of letters followed by one or more digits; or either of the words ‘cat’, ‘dog’ or ‘mouse’ – and much more. After reading through this page and experimenting with the examples, you’ll know exactly how.
Note: The term regular expression comes from the mathematical theory on which this pattern matching method is based. It is often abbreviated as regexp or regex – here we’ll use regex, or in the plural, regexes.
Literal and Meta
In a word processor’s old-school Find function every character is interpreted literally. If you search for ‘Yes? No…’ it will highlight ‘Yes? No…’ – or nothing if these characters do not appear in the text. In a regex, however, some characters have special meaning – these are called meta characters. The most important meta characters are:
Expression
Description
.
Matches any character.
|
Either expression on its left and right side matches the target string. For example, ‘a|b’ matches ‘a’ and ‘b’.
[]
Any of the enclosed characters may match the target character. For example, ‘[ab]‘ matches ‘a’ and ‘b’. ‘[0-9]‘ matches any digit.
[^]
None of the enclosed characters may match the target character. For example, ‘[^ab]‘ matches all characters except ‘a’ and ‘b’. ‘[^0-9]‘ matches any non-digit character.
*
Character to the left of the asterisk in the expression should match 0 or more times. For example, ‘be*’ matches ‘b’, ‘be’ and ‘bee’.
+
Character to the left of the plus sign in the expression should match 1 or more times. For example, ‘be+’ matches ‘be’ and ‘bee’ but not ‘b’.
?
Character to the left of the question mark in the expression should match 0 or 1 time. For example, ‘be?’ matches ‘b’ and ‘be’ but not ‘bee’.
{num}
Character to the left of the enclosed number should match num times. For example, ‘be{2}’ matches ‘bee’ but not ‘be’.
()
Creates a group and ‘remembers’ the matching area of the string. Groups can be used to re-order parts of a string, e.g. when converting dates to a different format.
\
Escape character. If you want to use the character ‘\’ itself, you should use ‘\\’.
Confusing? This table is only meant as a short summary and reference – the meaning of all of these expressions will be clarified in the areas below.
For now, let’s focus on the first one, the dot. In a regex it means ‘any character may stand here’. So the expression ‘No…’ in a regex will match any of the following:
· Notes
· Notte
· No…
· No&%X
 
So what do you need to write in a regex to match precisely ‘No…’ and no other text? To use a character that has a special meaning, you must ‘escape’ it: that is, precede with a backslash. Thus, ‘No\.\.\.’ will match exactly ‘No…’ and nothing else.
How to test regular expressions
In memoQ regexes are used to define segmentation rules and auto-translation rules, but not to search for text. So how can you sharpen your skills? Here’s a trick to ‘abuse’ auto-translation rules to experiment with regular expressions. Create a test project, and in the Settings pane of Project home click the Auto-translation rules tab. In the dialog that appears, delete every rule already there, and enter a rule of your own. For that rule, also add a replace order rule so that you see the dialog fields filled as shown below. (What a replace order rule means and why you need it here will be explained below.)

MemoQ regexp 1 Regular expressions

Now click Preview, type the text shown below in the Before auto translation box, and click the Preview button. You will see the following:

MemoQ regexp 2 Regular expressions

The ‘x’ in the Replace order rules field tells memoQ to replace text which the specified regex matches with a letter ‘x’ – that’s how you know that your regex is working in this experiment. In the Auto translation preview dialog you can see exactly which parts of the text you provided are replaced by an ‘x’, allowing you to test your regex.
Character classes
Now that we’ve covered the dot and know how to experiment with new regexes, let’s move on to some more serious expressions. Brackets in regexes allow you to specify a set of characters, or a character class. ‘[ab][01]‘ will match two-character-long sequences where the first character is either an ‘a’ or a ‘b’, and the second is either a ’0′ or a ’1′. This yields 4 possible matches: ‘a0′, ‘b0′, ‘a1′, ‘b1′.
Character classes can be used to express things like ‘a digit followed by a comma or an exclamation mark’ – which could be expressed as ‘[0123456789][,!]‘. This, however, would be a very inconvenient thing to write. Regexes know better: you can specify a range of characters by writing ‘[0-9][,!]‘, which is exactly the same as the previous expression.
Note: Can you use ranges to say ‘match an alphabetical letter’? Yes and no. A typical solution to do this used to be ‘[a-z]‘, which matches any of the letters between a and z. Keep in mind, however, that MmemoQ works with many different languages which often have special characters in their alphabet. The Icelandic letter ‘đ’, for instance, is definitely not in the range a-z. Therefore memoQ uses a special extension to deal with alphabetical letters, which will be described below.
Also, keep in mind that all letters in memoQ regexes are interpreted in a case-sensitive way. Thus, ‘[a-z]‘ will match ‘f’ but not ‘F’.
Besides specifying what you want to match, you can also use character classes to specify what not to match. The regex ‘[^0a].’ will match an infinite number of two-character sequences, so long as the first character is not ’0′ or ‘a’.
Escape sequences
As you saw above, you can specify the original meaning of the special meta characters by preceding them with a backslash (‘\’), or escaping them. There are also other practical escape sequences available. The ones most important for the purposes regexes are used for in memoQ are:
Sequence
Description
\s
Whitespace: space, tab or newline
\S
Anything but whitespace
\t
Tab
\n
Newline
\d
Digit (between 0 and 9)
\D
Anything but digits
\w
Alphanumeric character and underscore
\W
Anything but alphanumeric characters
Quantifiers
Now that you’ve learned to specify a set of alternative characters to match at a given position, it’s time to move down the road and tell memoQ how many characters to match. The special characters ‘*’ and ‘+’, and the expression {num} are used for this purpose.
· The regex ‘x+’ will match a sequence of characters which consists of one or more ‘x’s – thus, ‘x’, ‘xx’, ‘xxx’ and so on.
· The regex ‘x{3}’ will match a sequence of characters which consists of exactly 3 ‘x’s – thus, ‘xxx’, but not ‘x’ or ‘xx’. If the text is ‘xxxx’, the regex will match the first 3 ‘x’s and ignore the fourth. Visually: ‘xxxx’. For a parallel, remember that the traditional Find dialog will find the word ‘cat’ in ‘cats’.
· You can use the {num} quantifier in a special flavor by specifying a minimum or maximum value (or both). Thus, ‘x{3,5}’ will match between 3 and 5 ‘x’s; ‘x{3,}’ will match any sequence with at least 3 ‘x’s; and ‘x{,5}’ will match any sequence with at most 5 ‘x’s.
· Perhaps the funniest of the quantifiers is the asterisk (‘*’). Its meaning is ‘match zero or more of the given character’. What on earth is that good for? Well, you can say things like “match the letter ‘T’ preceded by some ‘a’s – or maybe none”. The corresponding regex is ‘a*T’, which will match ‘T’, ‘aT’, ‘aaT’ and so on.
· A little less exciting but no less useful quantifier is the question mark. Its meaning is to match zero or one of the character in front of it. Thus, ‘ax?y’ will match ‘ay’ and ‘axy’, but not ‘axxy’.
 
If you think quantifiers are fun, it’s time to combine them with character sets. Just as after characters, you can write quantifiers after character sets. ‘[0-9]+%’ will match a sequence of digits followed by a percentage sign; for instance, ’1%’ or ’99%’, but not ’10a%’.
Groups and Alternatives
Having covered character sets and quantifiers, there are only two standard regex features left to explore: groups and alternatives.
Using the pipe (‘|’) symbol you can join several smaller regexes to say ‘match either this, that or the other thing’. The regex ‘EUR|USD|GBP’ will match any of these words, and only these.
When working with alternatives you mostly need to group them together using parentheses to get the desired results. Let’s say you want a regex that matches any of these expressions: ‘EUR 15 million’, ‘USD 37 million’ and ‘GBP 5 million’. As a first try, you might be inclined to write ‘EUR|USD|GBP \d{1,} million’. This, however, will not do, as it only matches the following strings: ‘EUR’, ‘USD’ and ‘GBP [any natural number] million’. You need to group your alternatives together in the regex: ‘(EUR|USD|GBP) \d{1,} million’, where ‘EUR|USD|GBP’ can be either ‘EUR’ or ‘USD’ or ‘GBP’ and ‘\d{1,}’ can be any natural number starting from zero.
Replacing and reordering
For the purposes of segmentation, memoQ only uses regexes to match patterns in the translation document’s text. For auto-translation rules it also makes use of another powerful regex feature that has to do with groups: replacing and reordering parts of the matched text.
· Replacing a matched text with a single string:
 
You already saw a possible use for replacement in the How to test area of this page. There we defined the rather simplistic Replace order rule of ‘x’ to replace a regex match with the letter ‘x’ for the purposes of testing.
· Reordering and/or replacing parts of a matched text:
 
Here you need to group all those parts of the regex in pair of parentheses that you want to reference. The match enclosed in every pair of parentheses is remembered by memoQ and assigned a number starting with 1. When writing the replace order rule you can reference these remembered substrings by ‘$1′, ‘$2′ etc., in the order of the opening parenthesis’ appearance in the regex.
Using the previous regex example, you have to put also ‘\d{1,}’ in parentheses to make reordering of these currencies and their values possible: ‘(EUR|USD|GBP) (\d{1,}) million’. In the replace order rule you can reference ‘EUR|USD|GBP’ by ‘$1′, and ‘\d{1,}’ by ‘$2′. So if you want to change their order, the replace order rule could be ‘$2 Millionen $1′.
memoQ extensions
For the purposes of segmentation and defining auto-translatation rules it is often useful to work with lists of words – abbreviations, the names of months, currencies etc. In theory it would be possible to list these words grouped together as alternatives in the regular expressions, as you saw in the preceding area. However, doing so would result in very complicated and hard to maintain regexes. memoQ therefore introduces a special extension to regular expressions: custom lists.
Lists of words used in regular expressions can be defined in the Custom lists tab of the segmentation rules dialogs or of the auto-translation rules dialogs, or in the Translation pairs tab of the auto-translatables dialogs.
· The custom lists in the Custom lists tab of the segmentation rules dialogs should contain characters, abbreviations that are important for segmentation (e.g. ‘.’, ‘!’, ‘e.g.’).
· The custom lists in the Custom lists tab of the auto-translatables dialogs should contain words that have the same source and target form (e.g. ‘€’, ‘$’).
· The custom lists in the Translation pairs tab of the auto-translatables dialogs should contain source words with their target equivalents (e.g. In English-German projects ‘January’ should be translated as ‘Januar’, ‘February’ as ‘Februar’ etc.).
 
The name of a custom list must always start and end with a hash mark (‘#’). The words that make up a custom list are always interpreted as plain text, i.e. no characters are treated as meta characters with a special meaning.
Note: For segmentation rules memoQ defines one more special item: ‘#!#’. This extension does not influence regex matching in any way. Instead, it tells memoQ to introduce a segment break at the given location if the expression matches text in the imported document.
Example for using custom lists of the Custom lists tab of the auto-translation rules dialogs.
If you want memoQ to offer you ’15 Millionen EUR’ in the Translation results pane for every occurrence of ‘EUR 15 million’ and ’37 Millionen USD’ for ‘USD 37 million’. Create a custom list labeled ‘#currency#’ in the Custom lists tab containing ‘EUR’, ‘USD’ and ‘GBP’.

MemoQ regexp 3 Regular expressions

Now create the following regex ‘(#currency#) (\d{1,}) million’ (equivalent with ‘(EUR|USD|GBP) (\d{1,}) million’) for which the replace order rule could be ‘$2 Millionen $1′. The preview of the above regex and replace order rule will yield the following result:

MemoQ regexp 4 Regular expressions

If you want memoQ to offer you ’15 Millionen Euro’ in the Translation results pane for every occurrence of ‘EUR 15 million’ and ’37 Millionen Dollar’ for ‘USD 37 million’. Create a custom list labeled ‘#currency#’ in the Translation pairs tab containing the following translation pairs: ‘EUR’ – ‘Euro’, ‘USD’ – ‘Dollar’ and ‘GBP’ – ‘Pfund’.

MemoQ regexp 5 Regular expressions

Now create the following regex ‘(#currency#) (\d{1,}) million’ for which the replace order rule could be ‘$2 Millionen $1′. The preview of the above regex and replace order rule will yield the following result:

MemoQ regexp 6 Regular expressions
Source: http://memoq.helpmax.net

Wednesday, February 6, 2013

Bash script to access MyMemory

#!/bin/bash

##########################################################
# mymemory.sh                                            #
# use http://mymemory.translated.net                     #
# machine translation engine                             #
# from the command line                                  #
# by tony baldwin                                        #
# http://www.tonybaldwin.me                              #
# script at http://tonyb.us/mymem                        #
# released according to the GPL v. 3                     #
# see API at http://mymemory.translated.net/doc/spec.php #
##########################################################   

# getting variables
read -p "Language pair? (source|target, e.g. pt|en): " pair
read -p "Enter phrase to be translated: " ph
phrase=`echo $ph | sed 's/\ /%20/g'`

#sending variable to mymemory, writing to file
# what we get is a tmx file. We could write that to a file and keep it
# but we don't, here.
curl -s "http://mymemory.translated.net/api/get?q=$phrase&langpair=$pair&of=tmx" > mymemout.txt

# with some sed fu, strip that tmx to plain text for display in terminal
sed -i '
s/></>\n</g
s/<seg>\(.*\)<\/seg>/\1/g
s/<.*>//g
:a
/^$/d
t a
' mymemout.txt
sed -i '
N
s/\n/\t/' mymemout.txt
sed -i '/header/,+5d' mymemout.txt
sed -i "s/&apos;/\'/g" mymemout.txt
sed -i "s/&quot;/\'/g" mymemout.txt
sed -i 's/^[[:space:]]*//' mymemout.txt
sed -i '/^$/d' mymemout.txt
sed -i '0~2G' mymemout.txt

# display our results nicely in terminal
echo "----------------------------------------------------"
echo -e "$pair\n"
cat mymemout.txt
echo "----------------------------------------------------
translation courtesy http://mymemory.translated.net
mymem script by tony baldwin, http://tonyb.us/mymem
----------------------------------------------------"

# remove the output file
rm mymemout.txt
exit

Thursday, October 18, 2012

Ghid de exprimare corectă

Forme nominale (substantive, adjective, pronume)

Greșit Corect Explicații
băiatul al cărui carte
fata a cărui carte etc.
băiatul a cărui carte
fata a cărei carte
băiatul ale cărui cărți
fata ale cărei cărți
băieții a căror carte
fetele a căror carte
băieții ale căror cărți
fetele ale căror cărți

băiatul al cărui câine
fata al cărei câine
băiatul ai cărui câini
fata ai cărei câini
băieții al căror câine
fetele al căror câine
băieții ai căror câini
fetele ai căror câini
Mulți dintre noi facem acordul „cum s-o nimeri”. Totuși, există o regulă simplă, numită „acordul în cruce”: al/a/ai/ale se acordă cu obiectul (carte/cărți/câine/câini), iar cărui/cărei/căror se acordă cu posesorul (băiatul/fata/băieții/fetele).
fumător învederat
adevăr inveterat
fumător inveterat
adevăr învederat
Paronimele pot produce adesea confuzii! Întrucât e vorba de fumător înrăit și de adevăr evident, exprimarea corectă e cea indicată de ghid.
eu însuși etc. Masculin
eu însumi
tu însuți
el însuși
noi înșine
voi înșivă
ei înșiși

Feminin
eu însămi
tu însăți
ea însăși
noi însene
voi însevă
ele înseși (însele)
Pronume de întărire - vezi DEX.
cartea care am citit-o
omul care l-am întrebat
cartea pe care am citit-o
omul pe care l-am întrebat

cartea care mi-a plăcut
omul care mi-a răspuns
În toate cazurile avem de-a face cu propoziții subordonate atributive. În primele două, pe care este complement direct, ca și cartea, omul la care se referă, adică în cazul acuzativ, de aceea este nevoie și de prepoziția pe.

În ultimele două cazuri, care este subiect, ca și substantivele la care se referă, deci este la nominativ, de aceea nu este nevoie de prepoziția pe. Cartea care am citit-o este o contaminare între cele două construcții și este incorectă.
Mă doare apendicita.
Mă doare amigdalita.
Mă doare apendicele.
Mă dor amigdalele.
Apendicita și amigdalita sunt boli. Ele nu sunt părți ale corpului, deci nu au cum să doară. Totuși, construcția mă doare apendicita nu e așa de greșită cum pare. Se spune mă supără/necăjește/sâcâie etc. o boală, mă face să sufăr o boală, iar de aici la mă doare o boală, nu e decât un mic pas… La fel, se poate spune apendicita îmi provoacă dureri, deci, altfel spus, boala nu doare, dar dă durere.
Codri înverziți sunt frumoși.
Pantaloni albaștri s-au rupt.
Am discutat despre niște parametrii importanți.
Parametri cei mai importanți au fost discutați.
Codrii înverziți sunt frumoși.
Înverziții codri freamătă.
Pantalonii albaștri s-au rupt.
Am discutat despre niște parametri importanți.
Parametrii cei mai importanți au fost discutați.
Substantivele masculine au, la forma de plural articulat cu articol hotărât, doi i (sau trei, în cazul cuvintelor ca uliii, vizitiii, copiii). Când există un adjectiv antepus substantivului, el preia accentul: codrii înverziți, dar înverziții codri. În sintagma niște parametri importanți, articolul este nehotărât (niște), așadar toate cuvintele se scriu cu un singur i.
copii se joacă

cobaiii sunt rozătoare
un copil
doi copii
copiii se joacă

un cobai
doi cobai
cobaii sunt rozătoare
În cele mai multe cazuri, forma de plural articulat a substantivelor masculine se formează prin adăugarea articolului hotărât -i la forma nearticulată. Substantivele care au doi i la plural (copii, ulii, vizitii) capătă încă unul în forma articulată (copiii, uliii, vizitiii), iar substantivele care au un singur i la plural (oameni, cobai) vor avea doi i în forma articulată (oamenii, cobaii).
cea mai bine plătită doctoriță cel mai bine plătită doctoriță Formarea superlativului cu expresia cel mai se referă, în acest caz, la adverbul bine, nu la adjectivul plătită. Doctorița nu este cea mai plătită, ci cea plătită cel mai bine. Și, întrucât adverbele nu au gen, număr sau caz, superlativul se formează implicit cu cel pus la masculin.

Se vede mai ușor forma corectă inversând topica: Doctorița cel mai bine plătită, nu Doctorița *cea mai bine plătită.
îmi place de cineva îmi place cineva Cineva este subiect gramatical (cineva îmi place), deci trebuie pus în cazul nominativ, fără prepoziția de.
preț scump preț mare Un produs este scump atunci când prețul său este mare. Preț scump este o struțo-cămilă.
sticlă de un kilogram sticlă de un litru Volumul se măsoară în litri. Dacă umplem o sticlă de un litru cu mercur, ea va cântări peste 13 kilograme, iar dacă o umplem cu ulei de floarea soarelui, ea va cântări numai 920 de grame! Deci sticlă de un kilogram este restrictiv sau impropriu, sintagma fiind valabilă doar în cazul unor anumite lichide cu densitatea apropiată de 1kg / litru – apă, bere etc.
ora una
ora doi
ora doisprezece
ora douăzeci și una
ora douăzeci și doi
ora unu
ora două
ora douăsprezece
ora douăzeci și unu
ora douăzeci și două
Ora unu/douăzeci și unu, deci numerale masculine pe lângă un substantiv feminin, constituie excepții, explicabile prin faptul că moștenesc forma inițială a felului cum era exprimat timpul, un ceas după miezul zilei/nopții, mai pe scurt, ceasul unu, iar prin rostire prescurtată, unu (e ceasul unu sau, simplu, e unu). Apoi, forma de masculin, deja impusă, s-a păstrat și pe lângă femininul oră: ora unu. În schimb, în cazurile ora două/douăsprezece/douăzeci și două, s-a impus forma de feminin, care este și cea de neutru plural: două ceasuri după miezul zilei/nopții, de unde ceasurile sau ceasul două, apoi ora două etc. Este de neînțeles cum cineva poate rosti ora doisprezece, atâta timp cât nu va spune niciodată ora doi!
Am luat un pix de la ei și i l-am dat înapoi. Am luat un pix de la ei și li l-am dat înapoi.
Am luat un pix de la ei și l-am dat înapoi (lor).
Strict vorbind, deoarece am dat pixul înapoi mai multor persoane, corect este ...li l-am dat.... Totuși, aceasta este una din situațiile când ambele construcții sunt de evitat. Un motiv este eufonia. Apoi, dacă ar fi vorba de un obiect feminin, construcția s-ar schimba: am luat o minge de la ei și le-am dat-o înapoi.
... datorită publicului și a încurajărilor acestuia... ... datorită publicului și încurajărilor acestuia... După datorită se folosește dativul. Articolul posesiv a (al, ai, ale) este specific genitivului, deci nu are ce căuta aici.
Era crispat și zâmbea fortuit. Multe din marile descoperiri au fost făcute fortuit. Fortuit înseamnă „neprevăzut, inopinat, întâmplător”, nu „forțat”.
cartea anului acesta cartea anului acestuia Adjectivul pronominal demonstrativ se acordă în gen, număr și caz cu substantivul determinat.
condițiile cele mai optime
o listă foarte completă
condițiile optime
o listă completă
Adjectivele care la origine sunt comparative și superlative: exterior, interior, superior, inferior, optim, excelent sau cele care exprimă, prin sensul lor, superlativul: ultrasensibil, splendid, perfect nu formează grade de comparație.
De asemenea nu formează grade de comparație nici adjectivele care exprimă o însușire absolută: pozitiv, negativ, complet, mort, viu, principal, gravidă, mijlociu, prim etc.
Din cauza la vremea urâtă, n-am mai mers la munte. Din cauza vremii urâte, n-am mai mers la munte. Din cauza este o locuțiune prepozițională care cere întotdeauna cazul genitiv.
Le-am mulțumim la cei care m-au ajutat.
I-am mulțumit la unu dintre cei care m-au ajutat.
Le-am mulțumit celor care m-au ajutat.
I-am mulțumit unuia dintre cei care m-au ajutat.
Le-am mulțumit la trei dintre cei care m-au ajutat.
Le-am mulțumit la asemenea/astfel de oameni pentru ajutorul dat.
Celor, unuia, la trei, la asemenea/astfel de oameni sunt complemente indirecte. Ele răspund la întrebarea „cui i-am mulțumit?” (celor etc.), nu la întrebarea „la cine i-am mulțumit?” (la cei etc.). Acest gen de complement indirect stă întotdeauna în cazul dativ (celui etc.). Varianta la cei nu este propriu-zis o greșeală, ci mai curând un stil de vorbire neîngrijită sau o formă populară.
Limba literară acceptă construcția cu prepoziția la numai când complementul indirect este exprimat printr-un numeral invariabil (de exemplu trei) sau are ca determinant un adjectiv invariabil (de exemplu asemenea, astfel).
abrogarea legii adoptată acum un an abrogarea legii adoptate acum un an Când un atribut este exprimat prin adjectiv (provenit din participiul verbului a adopta, în acest caz), adjectivul se acordă întotdeauna în gen, număr și caz cu substantivul pe care îl determină. Aici legii este în cazul genitiv, deci și adoptate trebuie pus în cazul genitiv.
Ouălele sunt proaspete.
Încondeierea ouălelor este o tradiție frumoasă.
Ouăle sunt proaspete.
Încondeierea ouălor este o tradiție frumoasă.
Pentru a articula cu articolul hotărât pluralul substantivului ou, se adaugă articolul feminin –le la forma de nominativ plural: femei-femeile; cărți-cărțile; ouă-ouăle.. Vezi și definiția cu paradigma expandată.
Solicitatorul întrunește un summum de calități, care îl recomandă pentru a fi angajat. Solicitatorul întrunește o sumă de calități, care îl recomandă pentru a fi angajat.
Scriitorul a ajuns la un summum al calităților artistice greu de depășit.
Summum are sensul de gradul cel mai înalt, punct maxim. Folosirea lui cu sensul de sumă, sumedenie este greșită.
Doamna Ionescu este un filolog / politician / doctor / președinte / artist / profesor / muzician / sculptor renumit. Doamna Ionescu este o filologă / politiciană / doctoriță / președintă / artistă / profesoară / muziciană / sculptoriță renumită. Majoritatea profesiilor au și formă de feminin în limba română.
un medicament pentru ameliorarea durerii un medicament pentru atenuarea durerii Ameliorare înseamnă îmbunătățire, or durerea nu poate fi îmbunătățită. E corect, însă, ameliorarea stării de sănătate.
rata de promovabilitate la bac... rata de promovare la bac...
rata promovabilității la bac...
Rata de promovabilitate s-ar interpreta ca „procentul de însușire de a fi promovat”, ceea ce nu e normal ca exprimare. Dar, promovabilitate înseamnă și „acțiunea, starea de a promova”, ceea ce face posibilă a doua formă de construcție corectă.

Forme verbale

Greșit Corect Explicații
eu crez
tu crezi
el crează
creerea/creearea/creiarea lumii
eu creez
tu creezi
el creează
crearea lumii
Verbul a crea, deși aparent se termină în -ea, nu este un verb de conjugarea a II-a, ci de conjugarea I. Sufixul este -a, iar rădăcina este cre-. Pentru ușurință, conjugați-l ca și pe a lucra, înlocuind lucr- cu cre-: eu lucr-ez/cre-ez; tu lucr-ezi/cre-ezi; el lucr-ează/cre-ează etc. Formele crezi sau crez, crează aparțin verbului a crede: prima este pers. a II-a sing., indicativ prezent, iar celelalte două, forme populare ale aceluiași verb: eu crez, el/ea/ei/ele să crează.
eu creiez
eu agreiez
eu întemeez
eu încleez
eu creez
eu agreez
eu întemeiez
eu încleiez
Numai dacă infinitivul verbului se termină în -ia (a întemeia, a încleia), atunci litera -i- apare și în formele conjugate: eu întemeiez/încleiez..., eu întemeiam/încleiam..., eu întemeiai/încleiai..., eu am întemeiat/încleiat..., întemeind/încleind.
mi-ar place mi-ar plăcea Infinitivul verbului este a plăcea, iar condițional-optativul se formează cu verbul auxiliar a avea (în acest caz, ar) și cu infinitivul.
Fi cuminte!
fi punctual.
Să nu fi trist.
Nu fii fraier!
fii știut ce pierd, n-aș fii lipsit.
fii mândru dacă aș lua un premiu.
Promit că voi fii punctual.
Fii cuminte!
fii punctual.
Să nu fii trist.
Nu fi fraier!
fi știut ce pierd, n-aș fi lipsit.
fi mândru dacă aș lua un premiu.
Promit că voi fi punctual.
Se folosește fii doar la imperativ afirmativ (fii cuminte) și la conjunctiv afirmativ sau negativ (să fii punctual / să nu fii trist). În toate celelalte situații, se folosește fi.

venii și eu cu voi.
Cât am putut dormii!
veni și eu cu voi.
Cât am putut dormi!
În primul caz, verbul este la modul condițional-optativ, care se construiește întotdeauna cu forma de infinitiv a verbului. În al doilea caz, verbul este chiar la infinitiv. Formele eu venii, eu dormii sunt valabile pentru perfectul simplu.
Nu asta. Nu face asta. Imperativul negativ, pers. a II-a sing., se formează cu infinitivul verbului: nu mânca, nu vorbi, nu pleca. Deci, nu face.
nu se merită să aștepți
nu se există așa ceva
nu merită să aștepți
nu există așa ceva
Formele impersonale cu aspect reflexiv ale lui a merita și a exista au apărut, probabil, prin contaminare cu construcțiile similare de tipul nu se obișnuiește, nu se justifică, nu se face/cade, dar ele nu au nicio justificare.
Când am venit la tine, tu plecasei deja. Când am venit la tine, tu plecaseși deja. Forma verbului la indicativ, mai mult ca perfect, pers. a II-a sing., se construiește cu terminația -seși, nu –sei (valabilă pentru pers. I sing.): plecaseși, plăcuseși, merseseși, coborâseși, iubiseși.
A fost investit în funcția de ...
A învestit mult în afacere.
A fost învestit în funcția de ...
A investit mult în afacere.
Deși au o etimologie comună, verbele a investi („a cheltui/plasa bani într-un anumit scop, într-o anumită afacere”) și a învesti („a acorda cuiva în mod oficial un drept, o autoritate, o demnitate, o atribuție”) au evoluat diferit ca sens, de unde, probabil, nevoia de a le diferenția și formal, prin adoptarea formei învesti.
cere-ți voie înainte să plecați.
Nu trage-ți!
Cereți drepturile tale.
Trageți pătura (pe tine).
cereți voie înainte să plecați.
Nu trageți!
Cere-ți drepturile tale.
Trage-ți pătura (pe tine).
Când -ți apare ca desinență pentru indicarea pers. a II-a plural a verbelor, se scrie, desigur, lipit de verb: voi cereți, voi trageți. Dar se scrie despărțit prin cratimă de un verb la imperativ, când -ți este forma prescurtată a pronumelui îți, forma de dativ a lui tu, care în astfel de construcții are rol de pronume posesiv, înlocuind sau doar întărind pronumele posesiv propriu-zis: cere-ți drepturile = cere drepturile tale; trage-ți pătura = trage pătura (ta) pe corpul tău; pune-ți pălăria pe cap = pune pălăria (ta) pe capul tău.
eu crap (de râs, de ciudă).
tu crapi (de râs, de ciudă).
el se înșeală
vrea să (te) înșale
el/ea se așează
aibe parte
eu crăp (de râs, de ciudă).
tu crăpi (de râs, de ciudă).
el se înșală
vrea să (te) înșele
el/ea se așază
aibă parte
Formele corecte sunt stabilite de comisiile Academiei Române abilitate să instituie normele ortografice. Forma înșale există doar pentru sensul învechit „a pune șaua pe...” (astăzi verbul folosit pentru aceasta nu mai este a înșela, ci a înșeua).
De ce te râzi? De ce râzi? A râde este verb intranzitiv, nu reflexiv.
a avansa înainte a avansa A avansa înseamnă a înainta.
De-te la o parte
Dădeți-vă jos.
Dă-te la o parte.
Dați-vă jos.
De, dădeți, ca forme de imperativ ale verbului a se da, sunt variante învechite, populare, incorecte.
Ce-s cu cărțile astea pe masă?
Ce sunt cu cărțile astea pe masă?
Ce-i cu cărțile astea pe masă?
Ce este cu cărțile astea pe masă?
Folosirea verbului -i (formă abreviată și modificată a lui este/e) la plural nu are legătură cu faptul că vorbim despre mai multe cărți, deoarece este vorba de o formă impersonală, fixă: ce-i cu cărțile astea/cartea asta sau pantoful ăsta/pantofii ăștia pe masă? Ce-i cu tine?
mă risc să dau un pronostic...
te riști să-l înfrunți pe șef?
risc să dau un pronostic...
riști să-l înfrunți pe șef?
Chiar dacă unele dicționare menționează că a risca este și reflexiv, aceste forme sunt învechite și nerecomandate.

Folosirea corectă a unor adverbe și prepoziții. Alte devieri ortografice. Expresii

Greșit Corect Explicații
Eu am decât trei picioare.
Mai lipsește decât Mihai.
Am decât 10000 lei.
Eu am numai trei picioare.
Mai lipsește doar Mihai.
Nu am decât 10000 lei.
Ca adverbe restrictive, în construcții afirmative se folosesc numai sau doar, iar în construcții negative se folosește decât.
Ne-am văzut doar odată în ultimul an.
A fost o dată ca niciodată...
O dată cu Ana, a venit și Barbu.
Era vesel și o dată s-a întristat.
Ne-am văzut doar o dată în ultimul an.
A fost odată ca niciodată... (cândva)
Odată cu Ana, a venit și Barbu. (concomitent)
Era vesel și odată s-a întristat. (deodată)
O dată este o construcție formată din numeralul o (una) și substantivul dată („caz, ocazie, situație în care se petrece ceva”) și indică o enumerare (o dată, de două ori). Odată este adverb, având mai mult sensuri: „cândva”, „concomitent”. Vezi și definițiile pentru dată, odată.
Numai știu ce să cred.
Nu mai tu știi ce s-a întâmplat.
Nu mai știu ce să cred.
Numai tu știi ce s-a întâmplat.
Se face confuzie între două situații foarte diferite, între cuvântul numai și un grupaj relativ aleatoriu, ocazional, nu mai. Numai este un adverb cu funcție de delimitare, cu același sens ca doar: numai/doar el a fost invitat (nu și alții); voi sta numai/doar o oră (nu mai multe). În sintagma nu mai, cele două componente își păstrează autonomia, nu fiind o simplă negație, iar mai, un element de cu totul altă natură, care, aici, indică încetarea acțiunii exprimate de verb: mai știu = încă știu, continui să știu; nu mai știu = am încetat (deja) să știu. Deci, față de simpla negație nu știu, mai aduce precizarea, nuanțarea că înainte am știut.
Plouă în continuu.
România este încontinuu progres.
Plouă încontinuu (incontinuu).
România este în continuu progres.
Încontinuu/incontinuu este adverb (echivalent cu mereu, întruna, neîntrerupt), ușor de recunoscut, deoarece determină un verb. Construcția în continuu apare atunci când continuu e adjectiv, deci determină un substantiv. Funcția de adjectiv este confirmată și de caracterul flexibil al cuvântului – în continuu progres; în continuă dezvoltare –, dar și de mobilitatea sintactică: în continuu progres/în progres continuu.
ascultă muzică la maxim/minim
maxim de profit cu un minimum efort
ascultă muzică (dată/emisă) la maximum/minimum
maximum de profit cu un minim efort
La maximum/minimum sunt locuțiuni adverbiale, compuse din prepoziția la plus substantivele maximum/minimum, și determină verbe: s-a enervat la maximum; a redus la minimum cheltuielile. Ca substantive, ele pot apărea și în alte contexte – în maximum 30 de minute...; este necesar un minimum de efort... Ca adjective, aceste cuvinte au formele maxim/minim și determină diferite substantive, putând suferi și modificări flexionare: valoare maximă, eforturi minime.
cartea după noptieră cartea de pe noptieră Deși marcat ca impropriu, sensul de pe al prepoziției după este recunoscut de DEX ca fiind acceptabil, ceea ce ni se pare o eroare (vezi după, sensul I.5). După cu sensul de pe este un regionalism nerecomandabil.
Până număr la trei să plecați de-aici! Până număr până la trei să plecați de-aici! Numărăm (de la unu) până la trei. Probabil prezența primului până determină ezitarea de a-l repeta, dar este necesar și cel de-al doilea.
eu/ei/ele sînt/sânt eu/ei/ele sunt Există multe argumente pro și contra trecerii, în 1993, de la ortografia sînt la ortografia sunt (ca și a revenirii la folosirea lui â), dar normele curente impun forma sunt. Forma sânt este greșită oricum!
ânger
a hotărâ
reântregire
hotărît
hotărînd
înger
a hotărî
reîntregire
hotărât
hotărând
La începutul și la sfârșitul cuvintelor se folosește numai î, ca și în cuvintele formate cu prefix, dacă î este prima literă din rădăcină (reînnoire, neîntors). Deci, participiul și gerunziul verbelor nu fac excepție: coborât-coborând etc.
intreprinde, intreprindere, intreprinzător... întreprinde, întreprindere, întreprinzător... Toate cuvintele din această familie se scriu (și se pronunță) doar cu î, nu cu i.
a înpodobi
a înproșca
a se înbuiba
a înbiba
a împodobi
a împroșca
a se îmbuiba
a îmbiba
Înainte de -b- sau -p-, în cuvintele românești, apare consoana -m-, nu -n.- Fac excepție cuvintele compuse (sânpetru, nonprofit) și cuvintele adoptate în română în forma originală (hornpipe, Istanbul).
anti-drog
ne-respectuos
răs-poimâine
antidrog
nerespectuos
răspoimâine
În general, în limba română prefixele se scriu lipite de cuvântul care le urmează și nu se despart prin cratimă. Numai în cazul derivărilor ocazionale, neconsacrate de dicționare, se despart prin cratimă: anti-prezidențial, anti-Ionescu, anti-orice etc.
Liniște! Să nu se audă musca! Liniște! Să se audă musca!
Liniște! Să nu se audă nici musca!
În primul caz, se cere să fie atât de liniște, încât să se audă bâzâitul unei muște; în al doilea, cererea e și mai categorică, să fie atât de liniște, încât să nu se audă absolut nici un zgomot.
a da sfoară în țară a da sfară/șfară în țară Confuzie ușor de înțeles între sfară/șfară („fum”) și sfoară, cu atât mai mult cu cât primul aproape a ieșit din uz. Expresia are la bază un vechi procedeu de comunicare la distanță, prin aprinderea unor focuri, mai precis, inițial, a da sfară în țară însemna a semnala ceva cu ajutorul fumului, de la un post de strajă, la altul. De aici, evoluția la a răspândi o veste, sensul actual.
câine sur la vânătoare câine surd la vânătoare Expresia are sensul: „ineficient, inutil, inadecvat, nepotrivit, nelalocul lui”, iar culoarea (sur) nu are niciun efect asupra performanțelor câinelui la vânătoare...
Sursa: http://dexonline.ro