Регулярные выражения на сложном примере

Я столкнулся с задачей: Надо написать проверку, что перед каждым символом ‘a’ в строке находится нечётное число символов. Например, для строк ‘b’ и ‘ba’ эта проверка должна выдавать true, а для строк ‘a’ и ‘aa’ — false.

Начнем решать эту задачу поэтапно, так как ее решение выглядит следующим образом

Понять его сразу довольно сложно, а некоторые пишут, что смотреть чужие решения по регулярным выражениям и вовсе бессмысленно, так как их не прочитать. Но я хочу развеять этот миф и покажу вам, как прочитать данное решение или как к нему придти за 15 минут.

Итак, начнем. Первое, что нужно сделать – это разобраться с элементарными вещами, а именно:

Подробнее можно прочитать в списке литературы и особенно тут.

Двигаемся дальше. Нам нужно создать шаблон, который будет удовлетворять любому числу любых нечетных букв, находящемуся перед одной буквой а для начала. Для этого можно воспользоваться следующим приемом: создаем шаблон для четного числа букв и добавляем еще одну букву.

Согласно обозначениям сверху, следующая запись означает, что шаблон требует 2 любые буквы, кроме а.

Теперь объединяем эту запись в круглые скобки и ставим после нее звездочку. Это означает, что теперь 2 буквы кроме буквы а могут встречаться любое число раз, включая ноль:

Если мы перед предыдущей записью добавим еще одну букву, не равную а в обязательном порядке, то мы получим в итоге шаблон, который требует либо 1 букву, либо нечетное их число:

Допишем букву а в конце, это означает, что перед а – любое нечетное число букв и сама буква а добавилась:

Список использованных ссылок:

  1. http://www.learn-javascript-tutorial.com/RegularExpressions.cfm
  2. http://www.regular-expressions.info/javascriptexample.html – Инструмент для тестирования выражений
  3. http://www.javascriptkit.com/javatutors/re.shtml
  4. http://www.sql.ru/forum/actualthread.aspx?bid=34&tid=858526
  5. http://www.codeproject.com/KB/dotnet/regextutorial.aspx
  6. – самая полезная для меня статья оказалась

  7. http://msdn.microsoft.com/ru-ru/library/28hw3sce.aspx
  8. http://www.rsdn.ru/article/alg/regular.xml
  9. http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx
  10. http://www.intuit.ru/department/ds/discrmath/1/ – немного дискретной математики и потом идет курс по конечным автоматам, полезно почитать

How to copy image from Excel(diagram) to Corel Draw using PDF

At first I tried to simply copy OLE Excel Diagram object to Corel Draw. I needed to make that diagram in eps format for TeX, that’s why I used Corel Draw. But it failed. OLE object was copied the wrong way and there were a lot of problems like this:

I solved this problem in the following way.

  1. Export diagram to pdf file with standarts. The trick is to create pdf file in Excel with special standart. Look at the following pictures:

  2. Then import that pdf file to corel draw so that corel draw will use it’s native elements(lines, text, etc).

[ad#newad]

Solution of problem in Latex Editor (LEd) with Pictures of *.eps type

I like LEd but today I met a problem during PDFLatex compiling of my source with picture of *.eps type. It was telling that “unknown graphics extension: .eps”. Let’s look at it(Click to enlarge):

I was very upset because all my work was done in LEd and I got pretty used to this editor and I didn’t want to change my editor to another, for example WinEDT or other. So I tried to solve this problem. And I found an answer here.

To solve this problem, try the following:

  1. Locate eps file in true directory and try to change it’s name
  2. Compile with LaTeX compilation and then DVI conversion to PDF.

VBScript for automatic opening of programs, files and folders

Here I will explain a simple VBScript that I wrote today to make opening of some programs and folders automatic. This problem occured in my work because I needed to open frequently my postgraduate dissertation and some other TeX files and needed to open some folders and other programs fastly when I need. So let’s look at the script:

Dim objShellApp, WshShell

'проверка на уверенность

Set WshShell = CreateObject ("WScript.Shell")
Set objShellApp = CreateObject ("Shell.Application")

a = WshShell.Popup ("Ты уверен(а), что хочешь запустить все нужные программы? =))",,"Подумай!", 4+32)
If a = 7 Then WScript.Quit

WshShell.CurrentDirectory = "C:\Program Files\LEd"
WshShell.Run "LEd.exe"
WshShell.Run "LEd.exe"
WshShell.Run "LEd.exe"
objShellApp.ToggleDesktop

WshShell.CurrentDirectory = "C:\totalcmd"
WshShell.Run "TOTALCMD.exe"
objShellApp.ToggleDesktop

WshShell.CurrentDirectory = "C:\Documents and Settings\wzbozon\Рабочий стол"
WshShell.Run "ImageSaver.exe"
objShellApp.ToggleDesktop

objShellApp.Open("C:\Documents and Settings\wzbozon\Рабочий стол\TeX Books")

WshShell.CurrentDirectory = "C:\Documents and Settings\wzbozon\Рабочий стол\Alwawee\Приложения Alwawee\TexRef"
WshShell.Run "TexDatabase.xlsx"

WshShell.CurrentDirectory = "C:\Program Files\Google\Chrome\Application"
WshShell.Run "chrome.exe"

WshShell.CurrentDirectory = "c:\Аспирантура\DIPLOM\"
WshShell.Run "final.doc"

objShellApp.ToggleDesktop

First of all I should say, that this is a usual text file, called StartAll.vbs, that is edited in NotePad++. It can be edited on usual Notepad also, but I strongly recommend you to use Notepad++.

Here, at first I create 2 objects, that are used to manipulate the file system in Windows Script Host. Then I ask with a popup window if the user is sure to run this script. I do this, because I don’t need to run script, if user or me just press two times on it, because this script makes a lot of things. Then Led.exe program is opened 3 times from a directory, where it is located and then Desktop is toggled. Then I open Total Commander, ImageSaver.exe and TeX Books folder. The rest is analogous. It is noteworthy that Excel and Word files can be opened directly with Run method.